GADT question

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Mon Oct 10 16:29:48 EDT 2005


Henrik Nilsson <nhn at Cs.Nott.AC.UK> writes:

>  > I get an error "No instance for (Fractional a) arising from the use of
>  > '/'"  This seems odd to me, since Div is constrained to have
>  > fractional arguments.  Is there something obvious I'm missing?
> 
> Unless GADTs are handled specially, and I don't think they are in this 
> case, this problem is not specific to GADTs but related to how
> type constraints on constructors are handled in general. Basically, a
> constraint on a constructor has no effect beyond beyond constraining 
> what the  constructor can be applied to (see the Haskell 98 report 
> 4.2.1). In particular, when you take a constructed value apart through
> pattern matching, the constraints do not come into play: hence the "no
> instance" message.

And in case anyone is wondering, you could fix the original program by
adding the constraint to the function signature:

    eval :: Fractional a => Term a -> a

although this is likely more constrained than the OP wanted.

Regards,
    Malcolm


More information about the Glasgow-haskell-users mailing list