@@ -17,22 +17,21 @@ record Iso a b where
18-- Isomorphism properties
18-- Isomorphism properties
20−||| Isomorphism is reflexive
20+||| Isomorphism is Reflexive
21isoRefl : Iso a a
21isoRefl : Iso a a
22−isoRefl = MkIso id id (\_ => Refl) (\_ => Refl)
22+isoRefl = MkIso id id (\x => Refl) (\x => Refl)
24||| Isomorphism is transitive
24||| Isomorphism is transitive
25isoTrans : Iso a b -> Iso b c -> Iso a c
25isoTrans : Iso a b -> Iso b c -> Iso a c
26isoTrans (MkIso to from toFrom fromTo) (MkIso to' from' toFrom' fromTo') =
26isoTrans (MkIso to from toFrom fromTo) (MkIso to' from' toFrom' fromTo') =
27− MkIso xto xfrom xtoFrom xfromTo where
27+ MkIso (\x => to' (to x))
28− xto : a -> c
28+ (\y => from (from' y))
29− xto = to' . to
29+ (\y => (to' (to (from (from' y)))) ={ cong (toFrom (from' y)) }=
32− xtoFrom : (z : c) -> xto (xfrom z) = z
33− xtoFrom z = rewrite toFrom $ from' z in toFrom' z
30+ (to' (from' y)) ={ toFrom' y }=
34− xfromTo : (x : a) -> xfrom (xto x) = x
31+ y QED)
32+ (\x => (from (from' (to' (to x)))) ={ cong (fromTo' (to x)) }=
35− xfromTo x = rewrite fromTo' (to x) in fromTo x
33+ (from (to x)) ={ fromTo x }=
37Category Iso where
36Category Iso where
38 id = isoRefl
37 id = isoRefl
@@ -100,7 +99,8 @@ eitherBotRight = isoTrans eitherComm eitherBotLeft
101||| Isomorphism is a congruence with regards to disjunction
100||| Isomorphism is a congruence with regards to disjunction
102eitherCong : Iso a a' -> Iso b b' -> Iso (Either a b) (Either a' b')
101eitherCong : Iso a a' -> Iso b b' -> Iso (Either a b) (Either a' b')
102+eitherCong {a = a} {a' = a'} {b = b} {b' = b'}
103−eitherCong (MkIso to from toFrom fromTo)
103+ (MkIso to from toFrom fromTo)
104 (MkIso to' from' toFrom' fromTo') =
104 (MkIso to' from' toFrom' fromTo') =
105 MkIso (eitherMap to to') (eitherMap from from') ok1 ok2
105 MkIso (eitherMap to to') (eitherMap from from') ok1 ok2
106 where eitherMap : (c -> c') -> (d -> d') -> Either c d -> Either c' d'
106 where eitherMap : (c -> c') -> (d -> d') -> Either c d -> Either c' d'
@@ -143,7 +143,9 @@ pairAssoc = MkIso to from ok1 ok2
144||| Conjunction with truth is a no-op
144||| Conjunction with truth is a no-op
145pairUnitRight : Iso (a, ()) a
145pairUnitRight : Iso (a, ()) a
146−pairUnitRight = MkIso fst (\x => (x, ())) (\_ => Refl) (\(_, ()) => Refl)
146+pairUnitRight = MkIso fst (\x => (x, ())) (\x => Refl) ok
147+ where ok : (x : (a, ())) -> (fst x, ()) = x
148||| Conjunction with truth is a no-op
150||| Conjunction with truth is a no-op
149pairUnitLeft : Iso ((), a) a
151pairUnitLeft : Iso ((), a) a
@@ -159,7 +161,8 @@ pairBotRight = isoTrans pairComm pairBotLeft
160||| Isomorphism is a congruence with regards to conjunction
162||| Isomorphism is a congruence with regards to conjunction
161pairCong : Iso a a' -> Iso b b' -> Iso (a, b) (a', b')
163pairCong : Iso a a' -> Iso b b' -> Iso (a, b) (a', b')
164+pairCong {a = a} {a' = a'} {b = b} {b' = b'}
162−pairCong (MkIso to from toFrom fromTo)
165+ (MkIso to from toFrom fromTo)
163 (MkIso to' from' toFrom' fromTo') =
166 (MkIso to' from' toFrom' fromTo') =
164 MkIso to'' from'' iso1 iso2
167 MkIso to'' from'' iso1 iso2
165 where to'' : (a, b) -> (a', b')
168 where to'' : (a, b) -> (a', b')
@@ -202,7 +205,7 @@ distribLeft = MkIso to from toFrom fromTo
203||| Products distribute over sums
206||| Products distribute over sums
204distribRight : Iso (a, Either b c) (Either (a, b) (a, c))
207distribRight : Iso (a, Either b c) (Either (a, b) (a, c))
205−distribRight = (pairComm `isoTrans` distribLeft) `isoTrans` eitherCong pairComm pairComm
208+distribRight {a} {b} {c} = (pairComm `isoTrans` distribLeft) `isoTrans` eitherCong pairComm pairComm
208-- Enable preorder reasoning syntax over isomorphisms
211-- Enable preorder reasoning syntax over isomorphisms
@@ -219,7 +222,7 @@ step a iso1 iso2 = isoTrans iso1 iso2
219-- Isomorphisms over Maybe
222-- Isomorphisms over Maybe
220||| Isomorphism is a congruence with respect to Maybe
223||| Isomorphism is a congruence with respect to Maybe
221maybeCong : Iso a b -> Iso (Maybe a) (Maybe b)
224maybeCong : Iso a b -> Iso (Maybe a) (Maybe b)
222−maybeCong (MkIso to from toFrom fromTo) = MkIso (map to) (map from) ok1 ok2
225+maybeCong {a} {b} (MkIso to from toFrom fromTo) = MkIso (map to) (map from) ok1 ok2
223 where ok1 : (y : Maybe b) -> map to (map from y) = y
226 where ok1 : (y : Maybe b) -> map to (map from y) = y
224 ok1 Nothing = Refl
227 ok1 Nothing = Refl
225 ok1 (Just x) = (Just (to (from x))) ={ cong (toFrom x) }= (Just x) QED
228 ok1 (Just x) = (Just (to (from x))) ={ cong (toFrom x) }= (Just x) QED
@@ -250,7 +253,7 @@ maybeVoidUnit = (Maybe Void) ={ maybeEither }=
252eitherMaybeLeftMaybe : Iso (Either (Maybe a) b) (Maybe (Either a b))
255eitherMaybeLeftMaybe : Iso (Either (Maybe a) b) (Maybe (Either a b))
253−eitherMaybeLeftMaybe =
256+eitherMaybeLeftMaybe {a} {b} =
254 (Either (Maybe a) b) ={ eitherCongLeft maybeEither }=
257 (Either (Maybe a) b) ={ eitherCongLeft maybeEither }=
255 (Either (Either a ()) b) ={ eitherAssoc }=
258 (Either (Either a ()) b) ={ eitherAssoc }=
256 (Either a (Either () b)) ={ eitherCongRight eitherComm }=
259 (Either a (Either () b)) ={ eitherCongRight eitherComm }=
@@ -260,7 +263,7 @@ eitherMaybeLeftMaybe =
262eitherMaybeRightMaybe : Iso (Either a (Maybe b)) (Maybe (Either a b))
265eitherMaybeRightMaybe : Iso (Either a (Maybe b)) (Maybe (Either a b))
263−eitherMaybeRightMaybe =
266+eitherMaybeRightMaybe {a} {b} =
264 (Either a (Maybe b)) ={ eitherComm }=
267 (Either a (Maybe b)) ={ eitherComm }=
265 (Either (Maybe b) a) ={ eitherMaybeLeftMaybe }=
268 (Either (Maybe b) a) ={ eitherMaybeLeftMaybe }=
266 (Maybe (Either b a)) ={ maybeCong eitherComm }=
269 (Maybe (Either b a)) ={ maybeCong eitherComm }=
@@ -285,8 +288,8 @@ maybeIsoS = MkIso forth back fb bf
285 fb (FS x) = Refl
288 fb (FS x) = Refl
287finZeroBot : Iso (Fin 0) Void
290finZeroBot : Iso (Fin 0) Void
288−finZeroBot = MkIso (void . uninhabited)
291+finZeroBot = MkIso (\x => void (uninhabited x))
289− void
292+ (\x => void x)
290 (\x => void x)
293 (\x => void x)
291 (\x => void (uninhabited x))
294 (\x => void (uninhabited x))