[英]Why do we put a 'where' after defining data types in Agda?
Suppose I wish to define Bool as a type, I would write:假设我希望将 Bool 定义为一种类型,我会写:
data Bool : Type where data Bool : 在哪里输入
I don't quite understand why I must keep 'where' at the end, what purpose does it play in the Syntax?我不太明白为什么我必须在最后保留“where”,它在语法中的作用是什么? Why was the above preferred over say:为什么上述优先于说:
data Bool : Type数据布尔:类型
Was this arbitrary or is there some deep logic underlying?这是武断的还是有一些深层的逻辑基础?
By the way, I am a total noob at programming, so please explain using most simple words.顺便说一句,我是一个编程菜鸟,所以请用最简单的词解释一下。
With the where
keyword, we can write the following:使用where
关键字,我们可以编写以下内容:
data Bool : Set where true false : Bool
Without the where
keyword, this would be如果没有where
关键字,这将是
data Bool : Set true false : Bool
but this would be ambiguous: true
could be defined to be an element of type Level
, in which case this would be defining a datatype at sort Set true
with a single constructor false
.但这将是模棱两可的: true
可以定义为Level
类型的元素,在这种情况下,这将使用单个构造函数false
在 sort Set true
中定义数据类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.