Re: Strange error in show for datatype
Dylan Thurston
Strictness alas matters. Here's the witness:
class Num a => ZeroList a where consZero :: a -> [a] consZero _ = 0:xs
Err, "Num a" is already a bad context by Simon's criterion because of "fromInteger", which is what ultimately causes the problem in this case.
Quite right. I overlooked the fact that the superclass constraint
"Num a" implicitly includes all the methods of Num in ZeroList for
these purposes.
Olaf Chitil
instance Show MyType where shows _ = ("element of my type" ++ )
The important thing here is that the non-strict shows method can make up any result it likes. I do think some sort of extended defaulting mechanism as suggested by Thomas Hallgren would be useful. Yes, we will occasionally choose confusing interpretations of e.g. "" vs []. On the other hand, I'm sure we can warn when defaulting in this way. But its not the magic bullet against the monomorphism restriction one might have hoped for... -Jan-Willem Maessen
participants (1)
-
Jan-Willem Maessen