【发布时间】:2015-07-12 19:48:10
【问题描述】:
我刚开始玩 Idris,并尝试在其中插入一些 Haskell 机器:
namespace works
data Auto a b = AutoC (a -> (b, Auto a b))
const_auto : b -> Auto a b
const_auto b = AutoC (\_ => (b, const_auto b))
但是,我现在想将 Auto a b 推广到 AutoM m a b 以获取一个额外的参数,以便它可以单子生成其输出,m 是单子。我的直觉是m 的类型为Type -> Type,但随后类型检查器抱怨这与(Type, Type) -> Type 不匹配。所以我试着让它多态一点:
namespace doesntwork
data AutoM : {x : Type } -> (m : x -> Type) -> (a : Type) -> (b : Type) -> Type where
AutoMC : (a -> m (b, AutoM m a b)) -> AutoM m a b
data Identity a = IdentityC a
Auto : Type -> Type -> Type
Auto = AutoM Identity
这至少是类型检查。但是当我尝试时:
const_auto : Monad m => {m : x -> Type } -> {a : Type} -> b -> AutoM m a b
const_auto b = AutoMC (\_ => return (b, const_auto b))
然而,这并不好:
When elaborating right hand side of Stream.doesntwork.const_auto:
When elaborating an application of function Prelude.Monad.return:
Can't unify
(A, B) (Type of (a, b))
with
(b, AutoM m4 a b) (Expected type)
而且我无法理解类型错误。当a 没有在const_auto 的定义中的任何地方使用时,为什么会提到(a, b) 的类型?我觉得AutoM 的定义本身已经有问题,但我真的不知道为什么或如何。
【问题讨论】: