2 | import Decidable.Equality
13 | {0 p : a -> b -> Type} ->
14 | ((x : a) -> (
b ** p x b)
) ->
15 | (f : (a -> b) ** (x : a) -> p x (f x))
16 | choice pr = (
(\ x => fst (pr x)) ** \ x => snd (pr x))
25 | {0 b : a -> Type} ->
26 | {0 p : (x : a) -> b x -> Type} ->
27 | ((x : a) -> (y : b x ** p x y)) ->
28 | (f : ((x : a) -> b x) ** (x : a) -> p x (f x))
29 | choice pr = (
(\ x => fst (pr x)) ** \ x => snd (pr x))
35 | curry : {0 p : a -> Type} -> ((x : a ** p x) -> c) -> ((x : a) -> p x -> c)
36 | curry f x y = f (
x ** y)
42 | uncurry : {0 p : a -> Type} -> ((x : a) -> p x -> c) -> ((x : a ** p x) -> c)
43 | uncurry f s = f s.fst s.snd
50 | bimap : {0 p : a -> Type} -> {0 q : b -> Type} ->
52 | (prf : forall x. p x -> q (f x)) ->
53 | (x : a ** p x) -> (y : b ** q y)
54 | bimap f g (
x ** y)
= (
f x ** g y)
57 | DecEq k => ({x : k} -> Eq (v x)) => Eq (DPair k v) where
58 | (
k1 ** v1)
== (
k2 ** v2)
= case decEq k1 k2 of
59 | Yes Refl => v1 == v2
76 | record Exists {0 type : Type} this where
77 | constructor Evidence
82 | curry : {0 p : a -> Type} -> (Exists p -> c) -> ({0 x : a} -> p x -> c)
83 | curry f = f . Evidence _
86 | uncurry : {0 p : a -> Type} -> ({0 x : a} -> p x -> c) -> Exists p -> c
87 | uncurry f ex = f ex.snd
90 | evidenceInjectiveFst : Evidence x p = Evidence y q -> x = y
91 | evidenceInjectiveFst Refl = Refl
94 | evidenceInjectiveSnd : Evidence x p = Evidence x q -> p = q
95 | evidenceInjectiveSnd Refl = Refl
98 | bimap : (0 f : a -> b) -> (forall x. p x -> q (f x)) -> Exists {type=a} p -> Exists {type=b} q
99 | bimap f g (Evidence x y) = Evidence (f x) (g y)
113 | record Subset type pred where
114 | constructor Element
119 | curry : {0 p : a -> Type} -> (Subset a p -> c) -> (x : a) -> (0 _ : p x) -> c
120 | curry f x y = f $
Element x y
123 | uncurry : {0 p : a -> Type} -> ((x : a) -> (0 _ : p x) -> c) -> Subset a p -> c
124 | uncurry f s = f s.fst s.snd
127 | elementInjectiveFst : Element x p = Element y q -> x = y
128 | elementInjectiveFst Refl = Refl
131 | elementInjectiveSnd : Element x p = Element x q -> p = q
132 | elementInjectiveSnd Refl = Refl
135 | bimap : (f : a -> b) -> (0 _ : forall x. p x -> q (f x)) -> Subset a p -> Subset b q
136 | bimap f g (Element x y) = Element (f x) (g y)
139 | Eq type => Eq (Subset type pred) where
140 | (==) = (==) `on` fst
143 | Ord type => Ord (Subset type pred) where
144 | compare = compare `on` fst
149 | Show type => Show (Subset type pred) where
150 | showPrec p (Element v _) = showCon p "Element" $
showArg v ++ " _"