2 | import public Data.Ops
7 | %hide Builtin.DPair.DPair.fst
8 | %hide Builtin.DPair.DPair.snd
12 | record (*) (a, b : Type) where
17 | %pair Data.Product.(*) π1 π2
18 | %name Data.Product.(*)
p1, p2
21 | elim : (a -> a') -> (b -> b') -> (a' -> b' -> c) -> a * b -> c
22 | elim f g m x = f x.π1 `m` g x.π2
25 | depCurry : {0 a, b : Type} ->
26 | {0 c : a -> b -> Type} ->
27 | ((x : a) -> (y : b) -> c x y) -> (p : a * b) -> c p.π1 p.π2
28 | depCurry f x = f x.π1 x.π2
31 | bi : (a -> x) -> (b -> y) -> a * b -> x * y
32 | bi f1 f2 p = elim f1 f2 (&&) p
36 | merge : (a -> c) -> (b -> c) -> (c -> c -> c) -> a * b -> c
42 | merge' : Monoid c => (a -> c) -> (b -> c) -> a * b -> c
43 | merge' f g = merge f g (<+>)
46 | Show a => Show b => Show (a * b) where
47 | show (a && b) = "\{show a} & \{show b}"
51 | swap : a * b -> b * a
52 | swap x = x.π2 && x.π1
56 | toPair : a * b -> (a, b)
57 | toPair x = (x.π1, x.π2)
61 | fromPair : (a, b) -> (a * b)
62 | fromPair x = fst x && snd x
75 | distribute : a * b -> c * d -> (a * c) * (b * d)
76 | distribute x y = (x.π1 && y.π1) && (x.π2 && y.π2)
79 | fork : (a -> b) -> (a -> c) -> a -> b * c
80 | fork f g x = f x && g x
83 | split : (a * b) * c -> (a * c) * (b * c)
84 | split ((a && b) && c) = (a && c) && (b && c)
88 | through : (a -> b -> c) -> (x -> y -> z) -> (a * x) -> (b * y) -> (c * z)
89 | through f g x y = f x.π1 y.π1 && g x.π2 y.π2
93 | curry : (a * b -> c) -> a -> b -> c
94 | curry f a b = f (a && b)
98 | uncurry : (a -> b -> c) -> a * b -> c
99 | uncurry f x = f x.π1 x.π2
102 | shuffle : (a * x) * (b * y) -> (a * b) * (x * y)
103 | shuffle ((a && x) && (b && y)) = (a && b) && (x && y)
106 | proj1Pair : (0 a, b : _) -> (a && b).π1 === a
107 | proj1Pair _ _ = Refl
110 | proj2Pair : (0 a, b : _) -> (a && b).π2 === b
111 | proj2Pair _ _ = Refl
114 | (^) : Type -> Nat -> Type
117 | (^) a (S n) = a * a ^ n
120 | assocL : (a * b) * c -> a * (b * c)
121 | assocL x = x.π1.π1 && (x.π1.π2 && x.π2)
124 | assocR : a * (b * c) -> (a * b) * c
125 | assocR x = (x.π1 && x.π2.π1) && x.π2.π2
128 | FreeProd : List Type -> Type
130 | FreeProd (x :: []) = x
131 | FreeProd (x :: (y :: xs)) = x * FreeProd (y :: xs)
136 | cartesian : (a, b) -> (x, y) -> ((a, x), (b, y))
137 | cartesian (z, v) (w, s) = ((z, w), (v, s))
141 | Prod : (n : Nat) -> (a : Type) -> Type
144 | Prod (S n) x = x * Prod n x
148 | toProduct : Vect n a -> Prod n a
149 | toProduct [] {n = Z} = ()
150 | toProduct (x :: []) {n = S 0} = x
151 | toProduct (x :: xs) {n = S (S k)} = x && toProduct xs
154 | projIdentity : (x : a * b) -> (x.π1 && x.π2) === x
155 | projIdentity (a && b) = Refl