From d1fe69d31f39d5481d739e592863e1126cfe0c35 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Tue, 18 Sep 2018 13:11:22 -0400 Subject: [PATCH] Expose option module to the rest of the program --- compiler/src/lib/tiger/tiger_opt.ml | 11 +++++++++++ compiler/src/lib/tiger/tiger_opt.mli | 5 +++++ compiler/src/lib/tiger/tiger_test.ml | 15 ++------------- 3 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 compiler/src/lib/tiger/tiger_opt.ml create mode 100644 compiler/src/lib/tiger/tiger_opt.mli diff --git a/compiler/src/lib/tiger/tiger_opt.ml b/compiler/src/lib/tiger/tiger_opt.ml new file mode 100644 index 0000000..cdacd0e --- /dev/null +++ b/compiler/src/lib/tiger/tiger_opt.ml @@ -0,0 +1,11 @@ +type 'a t = 'a option + +let map t f = + match t with + | None -> None + | Some x -> Some (f x) + +let get t ~default = + match t with + | None -> default + | Some x -> x diff --git a/compiler/src/lib/tiger/tiger_opt.mli b/compiler/src/lib/tiger/tiger_opt.mli new file mode 100644 index 0000000..719e854 --- /dev/null +++ b/compiler/src/lib/tiger/tiger_opt.mli @@ -0,0 +1,5 @@ +type 'a t = 'a option + +val map : 'a t -> ('a -> 'b) -> 'b t + +val get : 'a t -> default:'a -> 'a diff --git a/compiler/src/lib/tiger/tiger_test.ml b/compiler/src/lib/tiger/tiger_test.ml index 038cd84..4d3287d 100644 --- a/compiler/src/lib/tiger/tiger_test.ml +++ b/compiler/src/lib/tiger/tiger_test.ml @@ -28,18 +28,7 @@ open Printf module List = ListLabels module String = StringLabels -module Option : sig - type 'a t = 'a option - - val map : 'a t -> ('a -> 'b) -> 'b t -end = struct - type 'a t = 'a option - - let map t f = - match t with - | None -> None - | Some x -> Some (f x) -end +module Opt = Tiger_opt (* TODO: ~expect:Output of 'a | Exception of (exn -> bool) *) type t = @@ -214,7 +203,7 @@ let run tests = | Ok produced -> let (out_stat, out_msg) = match - Option.map expect_output (fun expected -> expected = produced) + Opt.map expect_output (fun expected -> expected = produced) with | None -> (Skip, "expected output not provided") -- 2.20.1