簡體   English   中英

在agda中已知的模式匹配

[英]Known pattern match in agda

粗略地說,我有

check : UExpr -> Maybe Expr

我有一個測試術語

testTerm : UExpr

我希望能成功check ,之后我想提取生成的Expr並進一步操作它。 基本上

realTerm : Expr
just realTerm = check testTerm

如果check testTerm結果是nothing ,這個定義將無法進行類型check testTerm 這可能嗎?

通常的交易是寫一些類似的東西

Just : {X : Set} -> Maybe X -> Set
Just (just x) = One -- or whatever you call the fieldless record type
Just nothing = Zero

justify : {X : Set}(m : Maybe X){p : Just m} -> X
justify (just x) = x
justify nothing {()}

如果m計算成功,則p的類型為One,並推斷出該值。

好吧,我找到了一種方法來做到這一點,這有點奇怪和神奇。

testTerm-checks : Σ Expr (\e -> check testTerm ≡ just e)
testTerm-checks = _ , refl

realTerm : Expr
realTerm = proj₁ testTerm-checks

這給了我heebie jeebies,但不一定是壞的方式。 仍然對其他方式感興趣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM