为什么不使用Elem typecheck?

时间:2016-03-08 23:13:23

标签: idris

我很困惑。

module Experiment

import Data.Vect

p1: Elem 5 [3,4,5,6]
p1 = There (There Here)

v : Vect 4 Int
v = 3 :: 4 :: 5 :: 6 :: Nil

p2: Elem 5 v
p2 = There (There Here)

p2的定义没有进行类型检查,而p1的定义却没有。我使用的是Idris 0.10.2。有什么我想念的吗?

1 个答案:

答案 0 :(得分:1)

类型声明中的小写名称被解释为隐式参数(如a中的length : List a -> Nat,实际上是length : {a : Type} -> List a -> Nat)。要引用定义的Vect,您可以使用大写名称或通过命名空间引用:

module Experiment

import Data.Vect

A : Vect 4 Int
A = 3 :: 4 :: 5 :: 6 :: Nil

p2: Elem 5 A
p2 = There (There Here)

a : Vect 4 Int
a = 3 :: 4 :: 5 :: 6 :: Nil

p3: Elem 5 Experiment.a
p3 = There (There Here)
相关问题