I have the following code:

>class FixCls fix where
>  fix :: f (fix f) -> fix f
>  xif :: fix f -> f (fix f)
>
>class Functor f => Algebra f a where
>  phi :: f a -> a
>  
>class Functor f => CoAlgebra f a where
>   psi :: a -> f a
>
>cata::(Algebra f a, FixCls fix) => fix f -> a
>cata = phi . map cata . xif
>
>ana::(CoAlgebra f a, FixCls fix) => a -> fix f
>ana  = fix . map ana  . psi

It works fine but now I want to define the following function:

>hylo::(Algebra f a, CoAlgebra f b) => b -> a
>hylo = cata . ana

The type system rejects it:

ERROR "hylomorphism.lhs" (line 22): Ambiguous type signature in type declaration

*** ambiguous type : (CoAlgebra a b, Algebra a c) => b -> c
*** assigned to    : hylo

I think I understand the reason, but my question is:

How can I define that function?




Reply via email to