[nhc-bugs] problems compiling

Malcolm Wallace Malcolm.Wallace@cs.york.ac.uk
Tue, 4 Dec 2001 16:14:53 +0000


> > Problem 2, when trying to compile for tracing:
>
>   module T1 where
>   instance (Enum a, Bounded a, Eq b) => Eq (a -> b) where
>     f1 == f2 = and [f1 x == f2 x | x <- [minBound .. maxBound]]
>
> >   Fail: The class Prelude.Enum has no instance for the type Prelude.R.
> >   Possible sources for the problem are: 9:6

Ok, the problem here is not so much a bug but more of a restriction
on how the tracing mechanism works.  There is a workaround, although
I'm afraid it may not be suitable for your application - declare a
newtype or data for the function arrow, e.g.

    module T1 where
    newtype Func a b = Func (a->b)
    instance (Enum a, Bounded a, Eq b) => Eq (Func a b) where
      (Func f1) == (Func f2) = and [f1 x == f2 x | x <- [minBound .. maxBound]]

Then you will need to wrap each function in a Func constructor before
doing the equality comparison.

Regards,
    Malcolm