Hello,

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:

Parsing.lhs:7:5:
    Pattern bindings (except simple variables) not allowed in instance 
declarations
      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
behave.

Cheers,

Bruno


_______________________________________________
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to