【发布时间】:2021-01-20 22:36:15
【问题描述】:
我刚开始使用 Agda,但了解一些 Haskell,想知道如何在 Agda 中定义 Store Comonad。
这是我到现在为止的:
open import Category.Comonad
open import Data.Product
Store : Set → Set → ((Set → Set) × Set)
Store s a = ((λ s → a) , s)
StoreComonad : RawComonad (λ s a → (Store s a))
StoreComonad = record
{ extract (Store s a) = extract s a
; extend f (Store s a = Store (extend (λ s' a' → f (Store s' a')) s) a
} where open RawComonad
现在我收到以下错误:
Parse error
=<ERROR>
extract s a
; extend f (Sto...
我不太确定我做错了什么。任何帮助,将不胜感激!谢谢!
编辑
我想我越来越近了。我使用匹配的 lambdas 替换了记录中的字段:
Store : Set → Set → ((Set → Set) × Set)
Store s a = ((λ s → a) , s)
StoreComonad : RawComonad (λ s a → (Store s a))
StoreComonad = record
{ extract = λ st → (proj₁ st) (proj₂ st)
; duplicate = λ st → Store (λ s → Store (proj₁ st) s) (proj₂ st)
; extend = λ g st → g (duplicate st)
} where open RawComonad
RawComonad 来自https://github.com/agda/agda-stdlib/blob/master/src/Category/Comonad.agda
并有签名
record RawComonad (W : Set f → Set f) : Set (suc f)
Store 基于 Haskell 中的 type Store s a = (s -> a, s)。
现在我得到的错误是:
(a : Set) → Σ (Set → Set) (λ x → Set) !=< Set
when checking that the expression λ a → Store s a has type Set
我想知道这个错误是否与这一行有关:
StoreComonad : RawComonad (λ s a → (Store s a))
我发现Agda中的编译错误信息并没有给出太多线索或者我还不能很好地理解它们。
【问题讨论】:
-
定义记录时不能进行模式匹配。请改用
where子句或匹配的 lambda。 -
感谢您指出这一点!我正在尝试根据
agda-stdlib-1.4中的extract = head和extend = unfold ∘′ < tail ,_>中的Stream 实现方式来实现Store。我仍在努力思考如何定义 StoreComonad 实例。我是否需要将右侧实现为商店具有的功能,即这些功能是否是pos、peek、seek等?