From 2979571b6d0d1c387ba94d644494daca9cd1c798 Mon Sep 17 00:00:00 2001 From: Niols Date: Wed, 23 Feb 2022 14:04:42 +0100 Subject: [PATCH 1/3] drop OCaml < 4.08 --- .github/workflows/ci.yml | 4 ---- dune-project | 1 + ppx_monad.opam | 1 + 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 04189b7..d337b91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,10 +12,6 @@ jobs: fail-fast: false matrix: ocaml-compiler: - - 4.04.x - - 4.05.x - - 4.06.x - - 4.07.x - 4.08.x - 4.09.x - 4.10.x diff --git a/dune-project b/dune-project index 60e259f..6993585 100644 --- a/dune-project +++ b/dune-project @@ -15,5 +15,6 @@ (name ppx_monad) (synopsis "A Syntax Extension for all Monadic Syntaxes") (depends + (ocaml (>= 4.08.0)) dune-configurator (ppxlib (>= 0.9.0)))) diff --git a/ppx_monad.opam b/ppx_monad.opam index 9e4da9c..75b1cea 100644 --- a/ppx_monad.opam +++ b/ppx_monad.opam @@ -9,6 +9,7 @@ homepage: "https://github.com/Niols/ppx_monad" bug-reports: "https://github.com/Niols/ppx_monad/issues" depends: [ "dune" {>= "2.7"} + "ocaml" {>= "4.08.0"} "dune-configurator" "ppxlib" {>= "0.9.0"} "odoc" {with-doc} From bcf3f0f4e710359dc837ab5c7fbe9ebaa21890a4 Mon Sep 17 00:00:00 2001 From: Niols Date: Wed, 23 Feb 2022 14:17:04 +0100 Subject: [PATCH 2/3] use Stdlib everywhere --- src/ppx/list/ppx_monad_ppx_list.ml | 5 +++-- src/ppx/option/ppx_monad_ppx_option.ml | 12 ++++++------ src/ppx/result/ppx_monad_ppx_result.ml | 12 ++++++------ src/ppx/seq/ppx_monad_ppx_seq.ml | 4 ++-- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/ppx/list/ppx_monad_ppx_list.ml b/src/ppx/list/ppx_monad_ppx_list.ml index 916de36..135583f 100644 --- a/src/ppx/list/ppx_monad_ppx_list.ml +++ b/src/ppx/list/ppx_monad_ppx_list.ml @@ -6,13 +6,14 @@ let mk_return ~loc x = let mk_bind ~loc e f = let (pcmap, cmap) = Ppx_monad_lib.fresh_variable () in let (pbind, bind) = Ppx_monad_lib.fresh_variable () in + (* re-implement concat_map, only in Stdlib.List since 4.10.0 *) [%expr let [%p pcmap] = fun f l -> let rec aux f acc = function - | [] -> List.rev acc + | [] -> Stdlib.List.rev acc | x :: l -> let xs = f x in - aux f (List.rev_append xs acc) l + aux f (Stdlib.List.rev_append xs acc) l in aux f [] l in let [%p pbind] = fun e f -> [%e cmap] f e in diff --git a/src/ppx/option/ppx_monad_ppx_option.ml b/src/ppx/option/ppx_monad_ppx_option.ml index 8d29dde..b30ef21 100644 --- a/src/ppx/option/ppx_monad_ppx_option.ml +++ b/src/ppx/option/ppx_monad_ppx_option.ml @@ -1,24 +1,24 @@ open Ppxlib let mk_return ~loc x = - [%expr Some [%e x]] + [%expr Stdlib.Option.Some [%e x]] let mk_bind ~loc e f = let (px, x) = Ppx_monad_lib.fresh_variable () in [%expr match [%e e] with - | Some [%p px] -> [%e f] [%e x] - | None -> None] + | Stdlib.Option.Some [%p px] -> [%e f] [%e x] + | Stdlib.Option.None -> Stdlib.Option.None] let mk_fail ~loc e = - [%expr let () = [%e e] in None] + [%expr let () = [%e e] in Stdlib.Option.None] let mk_catch ~loc e f = let (px, x) = Ppx_monad_lib.fresh_variable () in [%expr match [%e e] with - | Some [%p px] -> Some [%e x] - | None -> [%e f] ()] + | Stdlib.Option.Some [%p px] -> Stdlib.Option.Some [%e x] + | Stdlib.Option.None -> [%e f] ()] let () = Ppx_monad_lib.register "option" ~applies_on:"opt(ion)?" diff --git a/src/ppx/result/ppx_monad_ppx_result.ml b/src/ppx/result/ppx_monad_ppx_result.ml index e86ab5f..bc5a7a2 100644 --- a/src/ppx/result/ppx_monad_ppx_result.ml +++ b/src/ppx/result/ppx_monad_ppx_result.ml @@ -1,26 +1,26 @@ open Ppxlib let mk_return ~loc x = - [%expr Ok [%e x]] + [%expr Stdlib.Result.Ok [%e x]] let mk_bind ~loc e f = let (px, x) = Ppx_monad_lib.fresh_variable () in let (py, y) = Ppx_monad_lib.fresh_variable () in [%expr match [%e e] with - | Ok [%p px] -> [%e f] [%e x] - | Error [%p py] -> Error [%e y]] + | Stdlib.Result.Ok [%p px] -> [%e f] [%e x] + | Stdlib.Result.Error [%p py] -> Stdlib.Result.Error [%e y]] let mk_fail ~loc y = - [%expr Error [%e y]] + [%expr Stdlib.Result.Error [%e y]] let mk_catch ~loc e f = let (px, x) = Ppx_monad_lib.fresh_variable () in let (py, y) = Ppx_monad_lib.fresh_variable () in [%expr match [%e e] with - | Ok [%p px] -> Ok [%e x] - | Error [%p py] -> [%e f] [%e y]] + | Stdlib.Result.Ok [%p px] -> Stdlib.Result.Ok [%e x] + | Stdlib.Result.Error [%p py] -> [%e f] [%e y]] let () = Ppx_monad_lib.register "result.ok" ~applies_on:"ok|res(ult)?(.ok)?" diff --git a/src/ppx/seq/ppx_monad_ppx_seq.ml b/src/ppx/seq/ppx_monad_ppx_seq.ml index 36389db..c52d3b9 100644 --- a/src/ppx/seq/ppx_monad_ppx_seq.ml +++ b/src/ppx/seq/ppx_monad_ppx_seq.ml @@ -1,10 +1,10 @@ open Ppxlib let mk_return ~loc x = - [%expr Seq.return [%e x]] + [%expr Stlib.Seq.return [%e x]] let mk_bind ~loc e f = - [%expr Seq.flat_map [%e f] [%e e]] + [%expr Stdlib.Seq.flat_map [%e f] [%e e]] let () = Ppx_monad_lib.register "seq" ~mk_return ~mk_bind From 840095f276cb6565c1a3d6effaa8bd086a596a53 Mon Sep 17 00:00:00 2001 From: Niols Date: Wed, 23 Feb 2022 14:20:19 +0100 Subject: [PATCH 3/3] use `bind` function when available --- src/ppx/option/ppx_monad_ppx_option.ml | 6 +----- src/ppx/result/ppx_monad_ppx_result.ml | 7 +------ 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/ppx/option/ppx_monad_ppx_option.ml b/src/ppx/option/ppx_monad_ppx_option.ml index b30ef21..de8bcbe 100644 --- a/src/ppx/option/ppx_monad_ppx_option.ml +++ b/src/ppx/option/ppx_monad_ppx_option.ml @@ -4,11 +4,7 @@ let mk_return ~loc x = [%expr Stdlib.Option.Some [%e x]] let mk_bind ~loc e f = - let (px, x) = Ppx_monad_lib.fresh_variable () in - [%expr - match [%e e] with - | Stdlib.Option.Some [%p px] -> [%e f] [%e x] - | Stdlib.Option.None -> Stdlib.Option.None] + [%expr Stdlib.Option.bind [%e e] [%e f]] let mk_fail ~loc e = [%expr let () = [%e e] in Stdlib.Option.None] diff --git a/src/ppx/result/ppx_monad_ppx_result.ml b/src/ppx/result/ppx_monad_ppx_result.ml index bc5a7a2..a37464b 100644 --- a/src/ppx/result/ppx_monad_ppx_result.ml +++ b/src/ppx/result/ppx_monad_ppx_result.ml @@ -4,12 +4,7 @@ let mk_return ~loc x = [%expr Stdlib.Result.Ok [%e x]] let mk_bind ~loc e f = - let (px, x) = Ppx_monad_lib.fresh_variable () in - let (py, y) = Ppx_monad_lib.fresh_variable () in - [%expr - match [%e e] with - | Stdlib.Result.Ok [%p px] -> [%e f] [%e x] - | Stdlib.Result.Error [%p py] -> Stdlib.Result.Error [%e y]] + [%expr Stdlib.Result.bind [%e e] [%e f]] let mk_fail ~loc y = [%expr Stdlib.Result.Error [%e y]]