GADT question
Henrik Nilsson
nhn at Cs.Nott.AC.UK
Mon Oct 10 13:40:46 EDT 2005
Hi Garrett,
> 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.
It has been suggested a number of times that constraints on
constructors should have a more profound meaning, and
maybe GADTs make this even more desirable, as your example suggest.
Best regards,
/Henrik
--
Henrik Nilsson
School of Computer Science and Information Technology
The University of Nottingham
nhn at cs.nott.ac.uk
This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.
More information about the Glasgow-haskell-users
mailing list