
28 May
2009
28 May
'09
11:50 a.m.
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