[clean-list] Repeated type variable in multi-parameter type
classes
Arjen van Weelden
A.vanWeelden at cs.ru.nl
Tue Jun 20 09:43:30 MEST 2006
Hi,
This is a restriction of the current implementation of multiple
parameter classes in Clean. Could you use the following instead?
instance SubType a (Either b c) | SubType a b
where
inj x = Left (inj x)
prj (Left x) = prj x
prj _ = Nothing
The next restriction you will run into is that both instances
Subtype a (Either b c) overlap. In appears that in Haskell you can use
type class instances to guide/steer the type inference. You cannot do
such a thing in Clean, as far as I know.
kind regards,
Arjen
romildo at iceb.ufop.br wrote:
> 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
> _______________________________________________
> clean-list mailing list
> clean-list at science.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/clean-list
More information about the clean-list
mailing list