Reputation: 73
Can someone please explain how Read/Show works.. I cannot find any tutorials on it. I've been searching through crappy haskell documentation for 4 days now and i'm getting very frustrated.
Could someone please be a savior tonight and help me convert a int to a string so I can reverse the string value.
Thank you.
Edit.. adding my current code..
mult_add d s = d + 10*s
form_number_back d = foldr mult_add 0 d
form_number_front d = reverse[(show $ read (form_number_back(d)))]
Upvotes: 0
Views: 241
Reputation: 64740
Your question appears to be part of a running dialog between you and some other folks here on SO - which is fine by me - but trying to answer you question without the rest of the context is hard beyond suggesting you see the Learn you a Haskell tutorial on the topic:
http://learnyouahaskell.com/types-and-typeclasses
Upvotes: 1
Reputation: 23135
read
converts a string to an Int (in your case), whereas show
converts an Int to a string.
It looks like form_number_back
returns an Int
, so you just need to show
it, not read
it.
Also, show
returns a string (in your case, [Char]
) so there's no need to put another [...]
around the result.
Upvotes: 2
Reputation: 198123
Writing types out will help.
mult_add :: Int -> Int -> Int
form_number_back :: [Int] -> Int
read :: [Char] -> Int
show :: Int -> [Char]
reverse :: [a] -> [a]
Upvotes: 4