简体   繁体   English

Agda:通常/花括号相对于彼此和“:”符号的使用方式

[英]Agda: How usual/curly braces are used relative to each other and to ':' sign

I have trouble understanding this syntax.我很难理解这种语法。 I didn't find the answer to my quesion in the Agda tutorial manual.我没有在 Agda 教程手册中找到我的问题的答案。 The only thing I found was that (x: A) -> (y: A) -> B sugars to (x: A)(y: A) -> B which sugars into (xy: A) -> B , but this isn't the whole story.我发现的唯一一件事是(x: A) -> (y: A) -> B糖化为(x: A)(y: A) -> B糖化为(xy: A) -> B ,但是这还不是全部。

What troubles me is that type declaration:让我烦恼的是类型声明:

map: {AB: Set} -> (A -> B) -> List A -> List B

is fine, while很好,而

map: {AB: Set} (A -> B) -> List A -> List B

is not.不是。

Version with arrow between arguments arguments之间带箭头的版本

singleton: {A: Set} -> (x: A) → List A

is fine, while the same expression without arrow很好,而没有箭头的相同表达式

singleton: {A: Set}(x: A) → List A

is still fine.还可以。

The version with ':' between arguments arguments 之间带':'的版本

data _≡_  {a}{P : Set a} (x : P) : P → Set a where
  refl : x ≡ x

is fine, while很好,而

data _≡_ :  ∀{a}{P : Set a} (x : P) →  P → Set a where
  refl :  x ≡ x

is not.不是。

In Haskell there is just regular braces, each separated with arrows.在 Haskell 中只有常规大括号,每个大括号用箭头分隔。 In Agda there is a lot more syntactic sugar, which isn't covered that much.在 Agda 中有更多的语法糖,但没有涵盖那么多。

while尽管

data _≡_: ∀{a}{P: Set a} (x: P) → P → Set a where refl: x ≡ x

is not.不是。

This example parses fine;这个例子解析得很好; the error is from scope checking:错误来自 scope 检查:

Not in scope:
  x at ...
when scope checking x

This error is beyond the scope of this question.这个错误超出了这个问题的scope。 As you seem to be noticing, though, there is a lot of similarity between your two putative definitions of _≡_ : the symbol tells the parser that what follows should parse as a parameter list (like before the colon pertaining to the _≡_ ), but be understood as a list of Curried arguments.但是,正如您似乎注意到的那样,您对_≡_的两个假定定义之间有很多相似之处: 符号告诉解析器接下来的内容应该解析为参数列表(就像与_≡_相关的冒号之前_≡_ ),但可以理解为Curried arguments的列表。 The main practical use of is to distinguish between x → P x and ∀ x → P x . 的主要实际用途是区分x → P x∀ x → P x The former desugars to (_: x) → P x (ie, x is a type), while the latter desugars to (x: _) → P x (ie, x stands for some individual, and its type is deduced from the type of P ).前者脱糖为(_: x) → P x (即x是一个类型),而后者脱糖为(x: _) → P x (即x代表某个个体,其类型由P的类型)。

I think your other test cases can now mostly be worked out.我认为您的其他测试用例现在大部分都可以解决。 The following doesn't have a sugared form because the A → B argument isn't given a name.以下没有糖化形式,因为A → B参数没有给出名称。

What troubles me is that type declaration:让我烦恼的是类型声明:

 map: {AB: Set} -> (A -> B) -> List A -> List B

is fine, while很好,而

map: {AB: Set} (A -> B) -> List A -> List B

is not.不是。

You could instead write:你可以改为写:

 map : {A B : Set} (f : A -> B) -> List A -> List B

or或者

 map : {A B : Set} (_ : A -> B) -> List A -> List B

if you really wanted.如果你真的想要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM