Primitive types and Prelude shenanigans
Marcin 'Qrczak' Kowalczyk
qrczak@knm.org.pl
20 Feb 2001 17:07:28 GMT
Tue, 20 Feb 2001 08:33:46 -0800, Simon Peyton-Jones <simonpj@microsoft.com> pisze:
> I don't mind doing this, but can someone first give a brief
> justification about why it's a good idea, independent of the
> discussion that has taken place on this list?
Suppose we build an alternative Prelude with different numeric class
hierarchy, and decide that types for natural numbers should not have
'negate' defined, as it's obviously meaningless for them. We can put
'fromInteger' in some class and 'negate' in its subclass, and make
only the former instance for natural numbers.
So -9 :: Natural should be a compile error. Negation is already
an error for all expressions other than literals when negate has
a wrong type for them; literals should not be an exception.
Negated literals are still treated in a special way in patterns,
but -9 in a pattern should expand to testing equality with
negate (fromInteger 9), not fromInteger (-9), to catch types
which intentionally don't have negate defined.
--
__("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
\__/
^^ SYGNATURA ZASTĘPCZA
QRCZAK