Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=a05dc97065a18ef83eb5b8fcfeea9dfa07dcefbf7daf2e41f7fc09cfddea7f55
sha512=f4aba0549c93a67d935a3b1554c189db20efcf26c0d8474c9f015a252e17d7b641996e3d72ef466f537b83ef0ea6c35baa7d1d67788b51686d9c77da387973e8
Description
function%distr A x, _ | _, A x when p x -> e will result in function A x, _ when p x -> e | _, A x when p x -> e
Added to opam-repository:
README
ppx_distr_guards
OCaml ppx extension to distribute guards over or-patterns (Warning 57)
Problem
type t = A of int | B of int
let f = function
| A x, _ (* A 0, A 1 would match here and then fail the guard *)
| _, A x when x<>0 -> 1 (* warning 57 *)
| _ -> 2
(* sadly there's no easy way to have the guard checked for every pattern: *)
let f = function
| A x, _ when x<>0 -> 1
| _, A x when x<>0 -> 1 (* if these were big expressions, we would need to pull out a function for each case to avoid duplication *)
| _ -> 2 File "test.ml", line 28, characters 4-19:
Warning 57: Ambiguous or-pattern variables under guard;
variable x may match different arguments. (See manual section 8.5)Solution
Different possibilities (see test.ml). Decided on the following:
let f = function%distr (* applies to all cases, no brackets, does not compile w/o ppx *)
| A x, _ | _, A x when x<>0 -> 1
| _ -> 2Which will result in
let f = function
| A x, _ when x<>0 -> 1 | _, A x when x<>0 -> 1
| _ -> 2
Dev Dependencies (1)
-
odoc
with-doc
Optional Dependencies
None
Used by (1)
-
goblint
< "2.0.0"
Conflicts
None
Build status
Results of building ppx_distr_guards with each compiler on check.ci.ocaml.org, run of against opam-repository 8a77e58. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 0.3 (this version) | good | good | good | n/a | n/a |
| 0.1 | good | good | good | good | good |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure