2 | import public Data.Ops
7 | %hide Builtin.DPair.DPair.fst
8 | %hide Builtin.DPair.DPair.snd
12 | record (*) (a, b : Type) where
33 | %pair Data.Product.(*) p1 p2
34 | %name Data.Product.(*)
p1, p2
37 | elim : (a -> a') -> (b -> b') -> (a' -> b' -> c) -> a * b -> c
38 | elim f g m x = f x.π1 `m` g x.π2
41 | depCurry : {0 a, b : Type} ->
42 | {0 c : a -> b -> Type} ->
43 | ((x : a) -> (y : b) -> c x y) -> (p : a * b) -> c p.π1 p.π2
44 | depCurry f x = f x.π1 x.π2
47 | bi : (a -> x) -> (b -> y) -> a * b -> x * y
48 | bi f1 f2 p = elim f1 f2 (&&) p
52 | merge : (a -> c) -> (b -> c) -> (c -> c -> c) -> a * b -> c
58 | merge' : Monoid c => (a -> c) -> (b -> c) -> a * b -> c
59 | merge' f g = merge f g (<+>)
62 | Show a => Show b => Show (a * b) where
63 | show (a && b) = "\{show a} & \{show b}"
67 | swap : a * b -> b * a
68 | swap x = x.π2 && x.π1
72 | toPair : a * b -> (a, b)
73 | toPair x = (x.π1, x.π2)
77 | fromPair : (a, b) -> (a * b)
78 | fromPair x = fst x && snd x
91 | distribute : a * b -> c * d -> (a * c) * (b * d)
92 | distribute x y = (x.π1 && y.π1) && (x.π2 && y.π2)
95 | fork : (a -> b) -> (a -> c) -> a -> b * c
96 | fork f g x = f x && g x
99 | split : (a * b) * c -> (a * c) * (b * c)
100 | split ((a && b) && c) = (a && c) && (b && c)
104 | through : (a -> b -> c) -> (x -> y -> z) -> (a * x) -> (b * y) -> (c * z)
105 | through f g x y = f x.π1 y.π1 && g x.π2 y.π2
109 | curry : (a * b -> c) -> a -> b -> c
110 | curry f a b = f (a && b)
114 | uncurry : (a -> b -> c) -> a * b -> c
115 | uncurry f x = f x.π1 x.π2
118 | shuffle : (a * x) * (b * y) -> (a * b) * (x * y)
119 | shuffle ((a && x) && (b && y)) = (a && b) && (x && y)
122 | proj1Pair : (0 a, b : _) -> (a && b).π1 === a
123 | proj1Pair _ _ = Refl
126 | proj2Pair : (0 a, b : _) -> (a && b).π2 === b
127 | proj2Pair _ _ = Refl
130 | (^) : Type -> Nat -> Type
133 | (^) a (S n) = a * a ^ n
136 | assocL : (a * b) * c -> a * (b * c)
137 | assocL x = x.π1.π1 && (x.π1.π2 && x.π2)
140 | assocR : a * (b * c) -> (a * b) * c
141 | assocR x = (x.π1 && x.π2.π1) && x.π2.π2
144 | FreeProd : List Type -> Type
146 | FreeProd (x :: []) = x
147 | FreeProd (x :: (y :: xs)) = x * FreeProd (y :: xs)
152 | cartesian : (a, b) -> (x, y) -> ((a, x), (b, y))
153 | cartesian (z, v) (w, s) = ((z, w), (v, s))
157 | Prod : (n : Nat) -> (a : Type) -> Type
160 | Prod (S n) x = x * Prod n x
164 | toProduct : Vect n a -> Prod n a
165 | toProduct [] {n = Z} = ()
166 | toProduct (x :: []) {n = S 0} = x
167 | toProduct (x :: xs) {n = S (S k)} = x && toProduct xs
170 | projIdentity : (x : a * b) -> (x.π1 && x.π2) === x
171 | projIdentity (a && b) = Refl