简体   繁体   English

在agda中已知的模式匹配

[英]Known pattern match in agda

Roughly, I have 粗略地说,我有

check : UExpr -> Maybe Expr

And I have a test term 我有一个测试术语

testTerm : UExpr

Which I hope will check successfully, after which I want to extract the resulting Expr and manipulate it further. 我希望能成功check ,之后我想提取生成的Expr并进一步操作它。 Basically 基本上

realTerm : Expr
just realTerm = check testTerm

Such that this definition would fail to typecheck if check testTerm turned out to be nothing . 如果check testTerm结果是nothing ,这个定义将无法进行类型check testTerm Is this possible? 这可能吗?

The usual deal is to write something like 通常的交易是写一些类似的东西

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 {()}

If m computes to a success, the type of p is One and the value is inferred. 如果m计算成功,则p的类型为One,并推断出该值。

Well I found one way to do it, which is sortof bizarre and magical. 好吧,我找到了一种方法来做到这一点,这有点奇怪和神奇。

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

realTerm : Expr
realTerm = proj₁ testTerm-checks

This gives me the heebie jeebies, but not necessarily in a bad way. 这给了我heebie jeebies,但不一定是坏的方式。 Still interested in other ways to do it. 仍然对其他方式感兴趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM