[Haskell-cafe] Usage of Read Class

Niklas Broberg niklas.broberg at gmail.com
Sun Mar 30 17:05:55 EDT 2008

>  I would like to ask something that results in when I have the following
>  commands
>  data Color = Red | Green | Blue | Indigo | Violet deriving (Enum,Show,Read)
>  (read.show) x
>  <interactive>:1:1:
>     Ambiguous type variable `a' in the constraint:
>       `Read a' arising from a use of `read' at <interactive>:1:1-4
>     Probable fix: add a type signature that fixes these type variable(s)

What the error message says is, it doesn't know which type to read to.
read has the type Read a => String -> a, and unless you tell it what
'a' is going to be, how would it know? If you say '(read.show) x ::
Color' it should work just fine.



More information about the Haskell-Cafe mailing list