From 24a26c8a230c27028892710896e029ee6cc232db Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Tue, 17 Mar 2020 09:04:42 -0700 Subject: [PATCH] [sledge] Move Import.Option to separate module Reviewed By: ngorogiannis Differential Revision: D20482757 fbshipit-source-id: 492674549 --- sledge/lib/import/import.ml | 23 +++-------------------- sledge/lib/import/import.mli | 16 +++------------- sledge/lib/import/option.ml | 27 +++++++++++++++++++++++++++ sledge/lib/import/option.mli | 17 +++++++++++++++++ 4 files changed, 50 insertions(+), 33 deletions(-) create mode 100644 sledge/lib/import/option.ml create mode 100644 sledge/lib/import/option.mli diff --git a/sledge/lib/import/import.ml b/sledge/lib/import/import.ml index f2111e1ea..7c8e1e5f3 100644 --- a/sledge/lib/import/import.ml +++ b/sledge/lib/import/import.ml @@ -12,8 +12,9 @@ include ( sig include (module type of Base + with module Option := Base.Option (* prematurely deprecated, remove and use Stdlib instead *) - with module Filename := Base.Filename + and module Filename := Base.Filename and module Format := Base.Format and module Marshal := Base.Marshal and module Scanf := Base.Scanf @@ -131,25 +132,7 @@ let filter_map_preserving_phys_equal filter_map t ~f = in if !change then t' else t -module Option = struct - include Base.Option - - let pp fmt pp_elt fs = function - | Some x -> Format.fprintf fs fmt pp_elt x - | None -> () - - let cons xo xs = match xo with Some x -> x :: xs | None -> xs - - module Monad_syntax = struct - type nonrec 'a t = 'a t - - let ( let+ ) x f = map ~f x - let ( and+ ) x y = both x y - let ( let* ) x f = bind ~f x - let ( and* ) x y = both x y - end -end - +module Option = Option include Option.Monad_infix include Option.Monad_syntax diff --git a/sledge/lib/import/import.mli b/sledge/lib/import/import.mli index 0609a4f20..a5a9afed4 100644 --- a/sledge/lib/import/import.mli +++ b/sledge/lib/import/import.mli @@ -12,8 +12,9 @@ include module type of ( sig include (module type of Base + with module Option := Base.Option (* prematurely deprecated, remove and use Stdlib instead *) - with module Filename := Base.Filename + and module Filename := Base.Filename and module Format := Base.Format and module Marshal := Base.Marshal and module Scanf := Base.Scanf @@ -102,18 +103,7 @@ val or_error : ('a -> 'b) -> 'a -> unit -> 'b or_error (** Extensions *) module Invariant : module type of Base.Invariant - -module Option : sig - include module type of Base.Option - - val pp : ('a_pp -> 'a -> unit, unit) fmt -> 'a_pp -> 'a option pp - (** Pretty-print an option. *) - - val cons : 'a t -> 'a list -> 'a list - - module Monad_syntax : Monad_syntax -end - +module Option = Option include module type of Option.Monad_infix include module type of Option.Monad_syntax with type 'a t = 'a option diff --git a/sledge/lib/import/option.ml b/sledge/lib/import/option.ml new file mode 100644 index 000000000..ffa0bd68f --- /dev/null +++ b/sledge/lib/import/option.ml @@ -0,0 +1,27 @@ +(* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + *) + +open ( + Base : + (module type of Base with module Format := Base.Format [@warning "-3"]) ) + +include Base.Option + +let pp fmt pp_elt fs = function + | Some x -> Format.fprintf fs fmt pp_elt x + | None -> () + +let cons xo xs = match xo with Some x -> x :: xs | None -> xs + +module Monad_syntax = struct + type nonrec 'a t = 'a t + + let ( let+ ) x f = map ~f x + let ( and+ ) x y = both x y + let ( let* ) x f = bind ~f x + let ( and* ) x y = both x y +end diff --git a/sledge/lib/import/option.mli b/sledge/lib/import/option.mli new file mode 100644 index 000000000..ac2eb9d2c --- /dev/null +++ b/sledge/lib/import/option.mli @@ -0,0 +1,17 @@ +(* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + *) + +open Base +open Import0 +include module type of Base.Option + +val pp : ('a_pp -> 'a -> unit, unit) fmt -> 'a_pp -> 'a option pp +(** Pretty-print an option. *) + +val cons : 'a t -> 'a list -> 'a list + +module Monad_syntax : Monad_syntax with type 'a t = 'a option