Comment on page
Read – readable types
Readclass supports reading and conversion of string representations of values into actual types using the
readmethod. All the basic types of Haskell are also instances of the
Readclass. Note that we sometimes have to specify the type to be read in cases where the intended type cannot be inferred:
ghci> read "False"
*** Exception: Prelude.read: no parse
ghci> read "False" :: Bool
That is, in the first case, the compiler does not know whether to read
"False"as a type of
Bool, so it throws an exception, while in the second case, we explicitly state that we want to read it as a
Bool. However, if we had some additional boolean function (e.g. negation) to be called on the read argument, the compiler would be able to automatically infer the wanted type:
ghci> not $ read "False"