Functional programming 为什么Monad是Set1?

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注释

我一直在尝试在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
注释它会产生以下错误:

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
更多关于宇宙多态性的信息,请参阅