[Haskell-cafe] Surprising bugs

Mark Carroll mark at chaos.x-philes.com
Wed May 12 19:27:54 EDT 2004


I clearly don't understand Haskell very deeply yet because I dealt with a
couple of interesting types of bug this week.

One sort was where, if I have,

f :: SomeType -> Stuff ...

f = whatever

g :: Stuff ...

g = f someValue

...then I can get an error that suggests that maybe I'm violating the
monomorphism restriction if I put in f's type but not g's. If I put both
in, it becomes happy.

Another sort was where, if I had an algebraic parametric type (is that the
name? Ord a => Foo a b c, etc.) then I couldn't have, say, a Maybe (Foo a
b c), where sometimes I called it with a (Just foo) and sometimes with a
Nothing, because with the Nothings it would complain about, erm, some
ambiguity to do with Ord a. However, it would be fixed if I made the Maybe
X argument into two arguments, Bool -> X, the Bool indicating if the X was
meant to have been a Nothing or a Just X.

I hope both (or either!) of those made sense. I don't have the code
immediately to hand to reproduce the details, but I just thought I'd try
to recall what they were because I found these compiler complaints
interesting. I don't fully understand what's happening, and I'm sure a
newbie would be quite bewildered. (-:

-- Mark


More information about the Haskell-Cafe mailing list