user1449653
user1449653

Reputation: 73

Explain how Read/Show works?

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

Answers (3)

Thomas M. DuBuisson
Thomas M. DuBuisson

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

Clinton
Clinton

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

Louis Wasserman
Louis Wasserman

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

Related Questions