[Haskell-beginners] Class instance for a type without a parameter
Peter Hall
peter.hall at memorphic.com
Sun Mar 11 16:57:30 CET 2012
Can someone remind me why I can't do this:
data Digit = D0 | D1 | D2 | D3 | D4 | D5 | D6 | D7 | D8 | D9
deriving (Eq, Ord, Show)
instance Num [Digit] where ... -- This isn't allowed
I could make Num a => [a] an instance of Num, but I can't make Digit
also an instance of Num because D8 + D5 is not a digit. So then I
could introduce a ConvertableToNum class, but I feel like I'd be
heading down a path with a lot of unnecessary extra type classes.
Thanks,
Peter
More information about the Beginners
mailing list