I'm trying to create a Cofree
structure by anamorphism, according to this post. But the compiler complains about type mismatch:
Expected type: Base (Cofree Term E) (E, Fix Term)
Actual type: CofreeF Term E (E, Fix Term)
But at the source code of recursion-schemes
package, there is an type instance definition:
type instance Base (Cofree f a) = CofreeF f a
How can I make the haskell compiler unify that type with this specific type instance equation successfully?
The code is almost the same as in the link:
import qualified Control.Comonad.Trans.Cofree as COFREEF
type E = Int
type Term = Maybe
annotate :: E -> Fix Term -> COFREEF.Cofree Term E
annotate = curry (ana coalg)
where
coalg :: (E, Fix Term) -> COFREEF.CofreeF Term E (E, Fix Term)
coalg (environment, Fix term) = environment COFREEF.:< fmap ((,)
environment) term
And the exact error message:
Couldn't match type ‘COFREEF.CofreeF Term E (E, Fix Term)’
with ‘Compose
Data.Functor.Identity.Identity
(COFREEF.CofreeF Maybe Int)
(E, Fix Term)’
Expected type: (E, Fix Term)
-> Base (COFREEF.Cofree Term E) (E, Fix Term)
Actual type: (E, Fix Term)
-> COFREEF.CofreeF Term E (E, Fix Term)
• In the first argument of ‘ana’, namely ‘coalg’
In the first argument of ‘curry’, namely ‘(ana coalg)’
In the expression: curry (ana coalg)