Counting Constructors
Tobias Haeberlein
T.Haeberlein@gmx.de
Thu, 19 Jul 2001 18:11:38 +0200 (MEST)
Thanks all for helping me!
For those, who are interested in it:
I got another solution of the problem:
Instead of defining
data Nest a = Zero | Succ a
I "lift" Nest to the class level:
data Zero a = Zero a
data Succ a = Succ a
class Nest a where
count :: a -> Either Int a
instance Nest (Zero a) where
count Zero = Left 0
instance Nest a => Nest (Succ a) where
count (Succ a) = case (count a) of
Left i -> (Left i+1)
Right _ -> (Right (Succ a)
Then my desired show-instance is easy to define by
instance Show (Zero a) where
show Zero = show 0
instance (Show a, Nest a) => Show (Succ a) where
show x = case (count x) of
Left i -> show i
Right (Succ x') -> show x'
(Funny, Conor McBride does a similar "lifting" throughout his
ingenious paper "Faking It: Simulating dependent types in Haskell"...)
-Tobi
--
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net
GMX Tipp:
Machen Sie Ihr Hobby zu Geld bei unserem Partner 1&1!
http://profiseller.de/info/index.php3?ac=OM.PS.PS003K00596T0409a