【问题标题】:Why can't dependent types in Idris handle this situation?为什么 Idris 中的依赖类型不能处理这种情况?
【发布时间】:2017-04-17 19:08:43
【问题描述】:

我想做以下事情:

data Foo : (a : Type) -> (b : Type) -> (c : a -> b -> Type) -> Type where
  Bar : a -> (c a) -> Foo a b c

但我收到以下错误:

When checking type of test.Bar:
When checking argument c to test.Foo:
    Type mismatch between
            Type -> Type (Type of c)
    and
            a -> b -> Type (Expected type)

    Specifically:
            Type mismatch between
                    Type
            and
                    b -> Type

这对我来说似乎应该是有效的。那就是c 在表达式Foo a b c 中有正确的类型,但Idris 认为它​​的类型是b -> Type,或者我认为的(c a)

是我遗漏了什么,还是 Idris 的限制?

【问题讨论】:

    标签: idris


    【解决方案1】:

    (c a) 的类型为b -> Type,而数据构造函数的所有字段都必须为Type 的类型。正如伊德里斯所说,这是一个错误。您的 c 类型构造函数接受两个参数,但您仅将其应用于单个 a

    【讨论】:

    • 有点吹毛求疵,但(c a) 的类型应该是b -> Type(因为b : Typec : a -> b -> Type)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-01
    • 1970-01-01
    • 2014-08-22
    • 1970-01-01
    相关资源
    最近更新 更多