[clean-list] Repeated type variable in multi-parameter type classes

romildo at iceb.ufop.br romildo at iceb.ufop.br
Sun Jun 18 20:11:21 MEST 2006


Hello.

I am porting a Haskell program to Clean, where type classes are used to
introduce some kind of subtyping:

//-------------------------------------------------------------
:: Either a b = Left a | Right b

class SubType sub sup
where
	inj :: sub -> sup
	prj :: sup -> Maybe sub

instance SubType a (Either a b)
where
	inj x        = Left x
	prj (Left x) = Just x
	prj _        = Nothing

instance SubType a (Either c b) | SubType a b
where
	inj x         = Right (inj x)
	prj (Right x) = prj x
	prj _         = Nothing
//-------------------------------------------------------------

But Clean rejects the first instance declaration because the type
variable a occours more than once.

How can I define that instance in Clean? It is not a problem for
Haskell.

Regards.

Romildo


More information about the clean-list mailing list