From 895d34a264d9d90adfe4f0618c3bb0663dc01615 Mon Sep 17 00:00:00 2001 From: Pierre-Marie Pédrot Date: Sat, 5 Dec 2015 12:53:20 +0100 Subject: Leveraging GADTs to provide a better Dyn API. --- lib/util.ml | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/util.ml') diff --git a/lib/util.ml b/lib/util.ml index a20dba0fc4..b67539918d 100644 --- a/lib/util.ml +++ b/lib/util.ml @@ -124,6 +124,7 @@ let delayed_force f = f () type ('a, 'b) union = ('a, 'b) CSig.union = Inl of 'a | Inr of 'b type 'a until = 'a CSig.until = Stop of 'a | Cont of 'a +type ('a, 'b) eq = ('a, 'b) CSig.eq = Refl : ('a, 'a) eq let map_union f g = function | Inl a -> Inl (f a) -- cgit v1.2.3 From 06fa0334047a9400d0b5a144601fca35746a53b8 Mon Sep 17 00:00:00 2001 From: Matej Kosik Date: Wed, 17 Feb 2016 10:32:40 +0100 Subject: CLEANUP: Renaming "Util.compose" function to "%" I propose to change the name of the "Util.compose" function to "%". Reasons: 1. If one wants to express function composition, then the new name enables us to achieve this goal easier. 2. In "Batteries Included" they had made the same choice. --- lib/util.ml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/util.ml') diff --git a/lib/util.ml b/lib/util.ml index b67539918d..0f79c10df1 100644 --- a/lib/util.ml +++ b/lib/util.ml @@ -87,7 +87,13 @@ let matrix_transpose mat = let identity x = x -let compose f g x = f (g x) +(** Function composition: the mathematical [∘] operator. + + So [g % f] is a synonym for [fun x -> g (f x)]. + + Also because [%] is right-associative, [h % g % f] means [fun x -> h (g (f x))]. + *) +let (%) f g x = f (g x) let const x _ = x -- cgit v1.2.3 From 0dfd0fb7d7c04eedfb3b161b9b5cfab103c17916 Mon Sep 17 00:00:00 2001 From: Hugo Herbelin Date: Sun, 13 Mar 2016 17:48:28 +0100 Subject: Adding a few functions on type union. --- lib/util.ml | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'lib/util.ml') diff --git a/lib/util.ml b/lib/util.ml index 0f79c10df1..cae996e332 100644 --- a/lib/util.ml +++ b/lib/util.ml @@ -132,9 +132,36 @@ type ('a, 'b) union = ('a, 'b) CSig.union = Inl of 'a | Inr of 'b type 'a until = 'a CSig.until = Stop of 'a | Cont of 'a type ('a, 'b) eq = ('a, 'b) CSig.eq = Refl : ('a, 'a) eq -let map_union f g = function - | Inl a -> Inl (f a) - | Inr b -> Inr (g b) +module Union = +struct + let map f g = function + | Inl a -> Inl (f a) + | Inr b -> Inr (g b) + + (** Lifting equality onto union types. *) + let equal f g x y = match x, y with + | Inl x, Inl y -> f x y + | Inr x, Inr y -> g x y + | _, _ -> false + + let fold_left f g a = function + | Inl y -> f a y + | Inr y -> g a y + | _ -> a +end + +let map_union = Union.map + +(** Lifting equality onto union types. *) +let equal_union f g x y = match x, y with + | Inl x, Inl y -> f x y + | Inr x, Inr y -> g x y + | _, _ -> false + +let fold_left_union f g a = function + | Inl y -> f a y + | Inr y -> g a y + | _ -> a type iexn = Exninfo.iexn -- cgit v1.2.3 From 3b3d98acd58e91c960a2e11cd47ac19b2b34f86b Mon Sep 17 00:00:00 2001 From: Hugo Herbelin Date: Fri, 15 Apr 2016 16:28:33 +0200 Subject: Cleaning unpolished commit 0dfd0fb7d7 on basic functions about union type. --- lib/util.ml | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'lib/util.ml') diff --git a/lib/util.ml b/lib/util.ml index cae996e332..009dfbe1c1 100644 --- a/lib/util.ml +++ b/lib/util.ml @@ -147,22 +147,10 @@ struct let fold_left f g a = function | Inl y -> f a y | Inr y -> g a y - | _ -> a end let map_union = Union.map -(** Lifting equality onto union types. *) -let equal_union f g x y = match x, y with - | Inl x, Inl y -> f x y - | Inr x, Inr y -> g x y - | _, _ -> false - -let fold_left_union f g a = function - | Inl y -> f a y - | Inr y -> g a y - | _ -> a - type iexn = Exninfo.iexn let iraise = Exninfo.iraise -- cgit v1.2.3