ListComprehensionNotation
We want to define a notation for Haskell-like list comprehension using Notation
, ie we want to denote
[ b | b <- l , P(b) ]
in Coq.
Assuming we have a variable list_comprehension
that has the following type:
Variable list_comprehension: forall A : Set, list A -> forall P : A -> Prop, is_decidable A P -> list A.
Implicit Arguments list_comprehension [A].
where
Definition is_decidable (A:Set) (P:A->Prop) := forall a, {P a} + {~(P a)}.
we can declare the following notation.
Notation "[ e | b <- l , Hp ]" := (map (fun b:_=> e) (list_comprehension l (fun b:_=>_ ) Hp)) (at level 1).
Now, for example, if
Hypothesis Zlt_decide:forall a, is_decidable Z (fun x=>x<a).
we can use the above notation to define the Haskell list [ y | y<-l , y<pivot]
where l:list Z
and pivot:Z
:
Definition elt_lt_x l pivot:= [ y | y <- l , (Zlt_decide pivot) ].
To the extent possible under law, the contributors of “Cocorico!, the Coq wiki” have waived all copyright and related or neighboring rights to their contributions.
By contributing to Cocorico!, the Coq wiki, you agree that you hold the copyright and you agree to license your contribution under the CC0 license or you agree that you have permission to distribute your contribution under the CC0 license.