`with f x` matches `false`, but cannot construct `f x == false`

前端 未结 1 1340
离开以前
离开以前 2020-12-22 10:48

A piece of code here:

-- transitivity
trans : {A : Set} {x y z : A} -> x == y -> y == z -> x == z
trans refl refl = refl

union-pair\' : {A : Set} -         


        
1条回答
  •  甜味超标
    2020-12-22 11:25

    It looks like you need to remember the fact that the following expression

    ismember (set-union (set-pair m n)) x
    

    is indeed equal to

    false
    

    This is a very common problem that comes from the way the 'with' construct works. By default, you don't have access to the proof element that connects the element on which you pattern match with the result of the pattern matching, that is, in your example, an element of type:

    ismember (set-union (set-pair m n)) x == false
    

    In order to get an element of this type, you need to use the 'inspect' idiom that is defined alongside the propositional equality in the standard library. More concretely, this means you'll have to add a new element to your pattern matching as follows:

    ... | ismember (set-union (set-pair m n)) x | inspect (ismember (set-union (set-pair m n)) x
    

    This will result in you having access both to 'false' and the proof element you require. For more information about the inspect idiom, see :

    • The wiki page on the with-abtraction : https://agda.readthedocs.io/en/v2.6.0.1/language/with-abstraction.html
    • The file PropositionalEquality.agda in the standard library, which provides the idiom as well as a quick description of how to use it
    • The file README/Inspect.agda in the standard library as well which provides a complete example on how and when to use the inspect idiom

    0 讨论(0)
提交回复
热议问题