Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Idris 创建一个零长度向量_Idris - Fatal编程技术网

Idris 创建一个零长度向量

Idris 创建一个零长度向量,idris,Idris,给定向量的这种类型,如何创建特定类型项的零长度向量 data Vect : Nat -> Type -> Type where VectNil : Vect 0 ty (::) : ty -> Vect size ty -> Vect (S size) ty VectNil String和我在REPL中尝试的所有变体都失败了。 期望VectNil像C#does中泛型列表的默认构造函数一样工作,这是不对的吗 新列表();//创建长度为零的字符串列表 VecNil是

给定向量的这种类型,如何创建特定类型项的零长度向量

data Vect : Nat -> Type -> Type where
  VectNil : Vect 0 ty
  (::) : ty -> Vect size ty -> Vect (S size) ty
VectNil String和我在REPL中尝试的所有变体都失败了。 期望VectNil像C#does中泛型列表的默认构造函数一样工作,这是不对的吗

新列表();//创建长度为零的字符串列表

VecNil
是值构造函数,它接受类型参数。在这里,您可以在REPL中看到它:

*x> :set showimplicits 
*x> :t VectNil 
 Main.VectNil : {ty : Type} -> Main.Vect 0 ty
Idris从上下文中推断这些隐式参数的值。但有时上下文没有足够的信息:

*x> VectNil
(input):Can't infer argument ty to Main.VectNil
可以使用大括号显式地为隐式参数提供值:

*x> VectNil {ty=String}
Main.VectNil {ty = String} : Main.Vect 0 String
或添加类型批注:

*x> the (Vect 0 String) VectNil 
Main.VectNil  : Main.Vect 0 String

在较大的程序中,Idris能够根据其使用位置推断类型。

谢谢您的回答。@AttilaKaroly您也可以使用
the
类似的:
the(Vect 0 String)VectNil
Anton,感谢您向我展示此替代方法。
*x> the (Vect 0 String) VectNil 
Main.VectNil  : Main.Vect 0 String