如何在 Agda 的 record/data 类型中存储一个函数?
How can I store a function inside record/data type in Agda?
我已阅读文档。它说:
The strict positivity condition rules out declarations such as
data Bad : Set where
bad : (Bad → Bad) → Bad
-- A B C
-- A is in a negative position, B and C are OK
since there is a negative occurrence of Bad in the type of the argument of the constructor. (Note that the corresponding data type declaration of Bad is allowed in standard functional languages such as Haskell and ML.).
但它没有说明是否有其他方法可以将函数存储在其他东西(如数据类型或记录类型)中。
我也试过这个,它也不能编译:
bin-op : ∀ {ℓ} (A : Set ℓ) → Set ℓ
bin-op A = A → A → A
record Storer {ℓ} (A : Set ℓ) : Set where
field
operator : bin-op A
那么如何在数据中存储函数 type/record type/something 否则我不知道?
问题出在
record Storer {ℓ} (A : Set ℓ) : Set where
部分。在这里你声明 Storer
属于 Set
宇宙,但是 Storer
包含 bin-op A
在 Set ℓ
宇宙中,并且记录不能更小比它的领域。因此,解决方法是将 Storer
定义为 Set ℓ
:
record Storer {ℓ} (A : Set ℓ) : Set ℓ where
严格肯定与问题完全无关。
旧的 wiki.
中描述了 Agda 中的全域多态性
我已阅读文档。它说:
The strict positivity condition rules out declarations such as
data Bad : Set where bad : (Bad → Bad) → Bad -- A B C -- A is in a negative position, B and C are OK
since there is a negative occurrence of Bad in the type of the argument of the constructor. (Note that the corresponding data type declaration of Bad is allowed in standard functional languages such as Haskell and ML.).
但它没有说明是否有其他方法可以将函数存储在其他东西(如数据类型或记录类型)中。
我也试过这个,它也不能编译:
bin-op : ∀ {ℓ} (A : Set ℓ) → Set ℓ
bin-op A = A → A → A
record Storer {ℓ} (A : Set ℓ) : Set where
field
operator : bin-op A
那么如何在数据中存储函数 type/record type/something 否则我不知道?
问题出在
record Storer {ℓ} (A : Set ℓ) : Set where
部分。在这里你声明 Storer
属于 Set
宇宙,但是 Storer
包含 bin-op A
在 Set ℓ
宇宙中,并且记录不能更小比它的领域。因此,解决方法是将 Storer
定义为 Set ℓ
:
record Storer {ℓ} (A : Set ℓ) : Set ℓ where
严格肯定与问题完全无关。
旧的 wiki.
中描述了 Agda 中的全域多态性