[Haskell-beginners] Doubts regarding the "read" function.
Venu Chakravorty
venuchv at gmail.com
Sat Dec 13 07:44:07 UTC 2014
Hello everyone,
I am new to Haskell and this might seem very naive, please bear with me.
=======================================
Prelude> read "4" + 4
8
Prelude> (read "4" :: Int) + 4
8
Prelude> read "hello " ++ "world"
"*** Exception: Prelude.read: no parse
Prelude> (read "hello" :: String) ++ " world"
"*** Exception: Prelude.read: no parse
=======================================
Could someone please explain why the last two statements don't work?
My understanding is that "read" has a type of "read :: (Read a) => String -> a".
So, "read "hello" " should give me an instance of type "Read" to which I am
appending the string "world" (just like the first 2 cases where I get
an instance of
"Read" ("Int" in this case) to which I am adding another "Int" and I
get a "Num" which
is then displayed). I expected to see "hello world" as the output.
Is it that the type "String" is not an instance of type class "Read"?
Please tell me what
I am missing here.
Regards,
Venu Chakravorty.
More information about the Beginners
mailing list