I've just started Haskell, and I've been trying to make a simple Number data type, which has a single Int like so:
data Number
= Num Int
deriving (Read, Show)
I then tried to do read "1234" :: Number hoping that would give something like Num 1234, but I seem to be getting an "Exception: Prelude.read: no parse" instead. Is there something else that I'm missing?
The instance you derive would give read "Num 1234" = Num 1234.
This is the behavior one expects for instances of Read, but if you really want a different behavior, you'll have to implement read for Number yourself (you can re-use Int's, though).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With