Functional programming 为什么Monad是Set1?
我一直在尝试在Agda中对Monad类型类进行编码。我已经走了这么远:Functional programming 为什么Monad是Set1?,functional-programming,monads,agda,dependent-type,Functional Programming,Monads,Agda,Dependent Type,我一直在尝试在Agda中对Monad类型类进行编码。我已经走了这么远: module Monad where record Monad (M : Set → Set) : Set1 where field return : {A : Set} → A → M A _⟫=_ : {A B : Set} → M A → (A → M B) → M B 所以Monad“instance”实际上只是传递的函数的记录。问题:为什么Monad是排序Set1?用Set注释
module Monad where
record Monad (M : Set → Set) : Set1 where
field
return : {A : Set} → A → M A
_⟫=_ : {A B : Set} → M A → (A → M B) → M B
所以Monad“instance”实际上只是传递的函数的记录。问题:为什么Monad
是排序Set1
?用Set
注释它会产生以下错误:
The type of the constructor does not fit in the sort of the
datatype, since Set₁ is not less or equal than Set
when checking the definition of Monad
我应该通过什么样的思维过程来确定
Monad
是Set1
而不是Set
?Agda拥有无限的宇宙层次结构Set:Set1:Set2:…
,以防止悖论(,)<代码>>>>>保留了这种层次结构:(Set->Set):Set1
,(Set1->Set):Set2
,(Set->Set2):Set3
,即A->B
所在的宇宙取决于A
和B
所在的宇宙:如果A
大于B
,然后A->B
与A
处于同一个宇宙中,否则A->B
与B
处于同一个宇宙中
您正在对Set
(在{A:Set}
和{A B:Set}
中)进行量化,因此返回的类型是和_⟫=_代码>位于Set1
,因此整个事情位于Set1
。对于显式宇宙,代码如下所示:
TReturn : (Set → Set) → Set1
TReturn M = {A : Set} → A → M A
TBind : (Set → Set) → Set1
TBind M = {A B : Set} → M A → (A → M B) → M B
module Monad where
record Monad (M : Set → Set) : Set1 where
field
return : TReturn M
_⟫=_ : TBind M
有关宇宙多态性的更多信息,请参见。Agda有一个无限的宇宙层次结构Set:Set1:Set2:…
,以防止悖论(,)<代码>>>>>
保留了这种层次结构:(Set->Set):Set1
,(Set1->Set):Set2
,(Set->Set2):Set3
,即A->B
所在的宇宙取决于A
和B
所在的宇宙:如果A
大于B
,然后A->B
与A
处于同一个宇宙中,否则A->B
与B
处于同一个宇宙中
您正在对Set
(在{A:Set}
和{A B:Set}
中)进行量化,因此返回的类型是和_⟫=_代码>位于Set1
,因此整个事情位于Set1
。对于显式宇宙,代码如下所示:
TReturn : (Set → Set) → Set1
TReturn M = {A : Set} → A → M A
TBind : (Set → Set) → Set1
TBind M = {A B : Set} → M A → (A → M B) → M B
module Monad where
record Monad (M : Set → Set) : Set1 where
field
return : TReturn M
_⟫=_ : TBind M
更多关于宇宙多态性的信息,请参阅