Counting Constructors
Marcin 'Qrczak' Kowalczyk
qrczak@knm.org.pl
17 Jul 2001 19:13:28 GMT
Tue, 17 Jul 2001 12:08:51 +0200 (MEST), Tobias Haeberlein <T.Haeberlein@gmx.de> pisze:
> show (Succ ( ... (Succ Zero)..)) = n
> (where n is the number of Succ's)
> and
>
> show (Succ ( ... (Succ x)..)) = show x
> (when x != Zero)
This is not possible in Haskell 98 - you can't overload an operation on
"any type except this one". There are no "negative assertions" or
"exceptions".
It might be possible in Hugs run with -98 option (define "instance
Count a" and "instance Count a => Count (Bind a)" and "instance Count
a => Show (Bind a)", where class Count has a function of type a->Int),
but I would not be surprised if it didn't work correctly in all cases,
e.g. if the answer was too small sometimes. Overlapped instances is
not a well behaved concept.
--
__("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
\__/
^^ SYGNATURA ZASTĘPCZA
QRCZAK