Counting Constructors

Tobias Haeberlein
Tue, 17 Jul 2001 12:08:51 +0200 (MEST)

I want a show - instance for that type:
	data Bind a = Zero | Succ a
resp. for the types (Bind ( ... (Bind a)...))

showing the following:

	show (Succ ( ... (Succ Zero)..))  =  n   
		(where n is the number of Succ's)

	show (Succ ( ... (Succ x)..)) = show x
		(when x != Zero)


And - a very similar problem - i'd like to have a 
function 'count' which get something of type 'Bind'
and returns a value of type (Either Int a):

	count ((Succ ( ... (Succ Zero)..)) = Left n  (n = #succ's)
	count (Succ ( ... (Succ x)..)) = Right x     (x != Zero)


Does anyone know, how to define those functions in haskell/hugs ??
(Are they defineable at all?)



GMX - Die Kommunikationsplattform im Internet.

GMX Tipp:

Machen Sie Ihr Hobby zu Geld bei unserem Partner 1&1!