[Haskell] Parsing bug in GHC 6.4.1 ?
bruno.oliveira at comlab.ox.ac.uk
Sun Jan 8 10:09:05 EST 2006
The following class definition:
> class Foo o where
> (:+) :: o -> o -> o
and even the following function definition:
> bar f (x,y) = x :+ y
are accepted by GHC. However, when I try to create
one instance of Foo:
> instance Foo Int where
> x :+ y = x + y
I get the following error message:
Pattern bindings (except simple variables) not allowed in instance
x :+ y = x + y
The same error still occurs if I change the infix operator to be (:+:).
However, if I define:
> class Foo3 o where
> (<+>) :: o -> o -> o
> instance Foo3 Int where
> x <+> y = x + y
Everything works as expected.
The only explanation that I have is that this is a (parsing) bug in GHC...
This is probably related to the fact that
> (:+) :: Int -> Int -> Int
> f :+ g = f + g
is an invalid definition (it complains that ":+" is not a data constructor).
I have not tried this code in other Haskell compiler (like Hugs) or even
previous versions of GHC. I would be interested to know how do those
More information about the Haskell