无法解析Haskell类型实例
我正试图通过变形来创建一个无法解析Haskell类型实例,haskell,type-families,recursion-schemes,Haskell,Type Families,Recursion Schemes,我正试图通过变形来创建一个共自由结构。但编译器抱怨类型不匹配: Expected type: Base (Cofree Term E) (E, Fix Term) Actual type: CofreeF Term E (E, Fix Term) 但是在递归方案包的源代码中,有一个类型实例定义: type instance Base (Cofree f a) = CofreeF f a 如何使haskell编译器成功地将该类型与此特定类型实例等式统一起来 代码与链接中的代码几乎相同: i
共自由结构。但编译器抱怨类型不匹配:
Expected type: Base (Cofree Term E) (E, Fix Term)
Actual type: CofreeF Term E (E, Fix Term)
但是在递归方案
包的源代码中,有一个类型实例定义:
type instance Base (Cofree f a) = CofreeF f a
如何使haskell编译器成功地将该类型与此特定类型实例等式统一起来
代码与链接中的代码几乎相同:
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
Cofree
只是一个类型同义词
newtype CofreeT f w a = CofreeT { runCofreeT :: w (CofreeF f a (CofreeT f w a)) }
type Cofree f = CofreeT f Identity
正是CofreeT
具有Base
实例:
type instance Base (CofreeT f w a) = Compose w (CofreeF f a)
-- Base (Cofree f a) ~ Base (CofreeT f Identity a) ~ Compose Identity (CofreeF f a)
这个问题的等式在道德上是等价的,但它不是一个足够好的近似值
用Compose包装你的coagebra。标识
annotate :: E -> Fix Term -> Cofree Term E
annotate = curry $ ana $ Compose . Identity . coalg
where
coalg :: (E, Fix Term) -> CofreeF Term E (E, Fix Term)
coalg (environment, Fix term) = environment :< fmap (environment,) term
annotate::E->Fix Term->Cofree Term E
注释=咖喱$ana$Compose。身份。煤
哪里
coalg::(E,固定期限)->固定期限E(E,固定期限)
coalg(环境,固定术语)=环境:
请在问题中包括您的代码,以及您使用的是什么版本的递归方案
该代码与链接中的注释
函数完全相同,术语
别名为可能
,而E
别名为Int
,而calcEnv
函数被const
替换。递归方案的版本是5.0.2Huh,在我看来,错误的第一部分(提到组合)与“预期的……实际的……”部分不一致,这看起来像是一个bug,但我可能遗漏了一些东西。什么ghc版本?ghc版本是8.2。2@jberryman不,GHC很好。这里的实际类型对应于消息中的第一种类型,预期类型对应于第二种类型。也就是说,消息中的类型是按“实际-预期-实际”顺序排列的。最后我发现我应该从Control.Comonad.Trans.Cofree
导入Cofree(…)
,从Control.Comonad.Cofree
导入递归方案的Cofree
。。。它有点有线。
annotate :: E -> Fix Term -> Cofree Term E
annotate = curry $ ana $ Compose . Identity . coalg
where
coalg :: (E, Fix Term) -> CofreeF Term E (E, Fix Term)
coalg (environment, Fix term) = environment :< fmap (environment,) term