I'm doing sort of a compiler in haskell and I came up to this problem:
This is the code I have for the moment:
data Command a = Input a | Print a
readCommand:: Read a => String -> Command a
readCommand entrada
| tokens!!0 == "INPUT" = Input (tokens!!1)
| tokens!!0 == "PRINT" = Print (tokens!!1)
where
tokens = words entrada
listInstr = lines entrada
but I get this error:
Couldn't match type 'a' with 'String'; 'a' is a rigid type variable bound by the type signature for readC:: Read a => String -> Command a
Expected type: [a] ; Actual type: [String]
Does this error mean that if I declare on the function that I have a string, type 'a' cannot be a String too?
Thanks for the help
...= Input (read $ tokens!!1)
... which will tryread
the words/tokens from your input-string into your typea
– Random Deva
but then only produced aString
- so if I sayreadCommand "INPUT 12" :: Command Int
you should see the problem – Random Dev