Provide the identity lens and verify composition identities

This commit is contained in:
milner committed 2019-02-24 07:41:34 +00:00
1 parent 28d28de6fa
commit d8c191be6d
3 files changed
+7

No files matched your search

+1
View File
@@ -12,3 +12,4 @@ let compose (outer_get, outer_put) (inner_get, inner_put) =
let _1 = (fun (left, _) -> left), (fun left (_, right) -> left, right) let _1 = (fun (left, _) -> left), (fun left (_, right) -> left, right)
let _2 = (fun (_, right) -> right), (fun right (left, _) -> left, right) let _2 = (fun (_, right) -> right), (fun right (left, _) -> left, right)
let _id = (fun value -> value), (fun value _ -> value)
+1
View File
@@ -8,3 +8,4 @@ val over : ('s, 't, 'a, 'b) lens -> f:('a -> 'b) -> 's -> 't
val compose : ('s, 't, 'a, 'b) lens -> ('a, 'b, 'c, 'd) lens -> ('s, 't, 'c, 'd) lens val compose : ('s, 't, 'a, 'b) lens -> ('a, 'b, 'c, 'd) lens -> ('s, 't, 'c, 'd) lens
val _1 : ('a * 'c, 'b * 'c, 'a, 'b) lens val _1 : ('a * 'c, 'b * 'c, 'a, 'b) lens
val _2 : ('c * 'a, 'c * 'b, 'a, 'b) lens val _2 : ('c * 'a, 'c * 'b, 'a, 'b) lens
val _id : ('a, 'b, 'a, 'b) lens
+5
View File
@@ -25,3 +25,8 @@ let () =
assert (set _1 "grey" (1, true) = ("grey", true)); assert (set _1 "grey" (1, true) = ("grey", true));
assert (over _2 ~f:string_of_int (false, 9) = (false, "9")); assert (over _2 ~f:string_of_int (false, 9) = (false, "9"));
assert (view (compose _1 _2) ((true, "grey"), ()) = "grey") assert (view (compose _1 _2) ((true, "grey"), ()) = "grey")
let () =
assert (set _id "grey" 9 = "grey");
assert (view (compose _id _1) (9, false) = view _1 (9, false));
assert (set (compose _2 _id) "grey" (true, 9) = set _2 "grey" (true, 9))