[Haskell-beginners] Haskell Generic Function Question
William Gilbert
gilbertw1 at gmail.com
Thu May 28 11:50:36 EDT 2009
I am trying to write a function that will covert either an integer or
an int into a list containing its digits.
ex. toIntegralList 123 -> [1,2,3]
I have written the following definition that tries to use read to
generically cast a string value to an Integral type that is the same
as the Integral passed in:
toIntegralList :: (Integral a) => a -> [a]
toIntegralList x = map (\c -> read [c] :: a) (show x)
I understand it would be very simple to just create two functions, one
that converts an Int and one that converts an Integer, however I was
wondering if there were any way to accomplish what I am trying to do
here.
Thanks In Advance,
Bryan
More information about the Beginners
mailing list