Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/c-cube/choice
Choice operator in OCaml, providing a backtracking monad
https://github.com/c-cube/choice
backtracking continuations monad ocaml pure
Last synced: 4 months ago
JSON representation
Choice operator in OCaml, providing a backtracking monad
- Host: GitHub
- URL: https://github.com/c-cube/choice
- Owner: c-cube
- License: bsd-2-clause
- Created: 2013-06-19T16:50:56.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2022-01-26T17:09:46.000Z (about 3 years ago)
- Last Synced: 2024-04-20T00:54:15.897Z (10 months ago)
- Topics: backtracking, continuations, monad, ocaml, pure
- Language: OCaml
- Homepage: https://c-cube.github.io/choice/
- Size: 61.5 KB
- Stars: 24
- Watchers: 4
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Choice [![build](https://github.com/c-cube/choice/actions/workflows/main.yml/badge.svg)](https://github.com/c-cube/choice/actions/workflows/main.yml)
Choice monad. See
[the Haskell library](http://hackage.haskell.org/packages/archive/logict/0.2.3/doc/html/Control-Monad-Logic.html)
or [this paper](http://homes.sice.indiana.edu/ccshan/logicprog/LogicT-icfp2005.pdf)See [online documentation](https://c-cube.github.io/choice/).
## Example
```ocaml
> #require "choice";;
> open Choice.Infix;;
> let c = Choice.lift2 (fun x y -> x,y)
(Choice.of_list [1;2;3;4]) (Choice.of_list ["1"; "3"]);;
val c : (int * string) Choice.t =
> let c2 = Choice.filter c (fun (x,y) -> x = int_of_string y);;
val c2 : (int * string) Choice.t =
> let c3 = Choice.take 2 c2;;
val c3 : (int * string) Choice.t =
> Choice.run_n 4 c3;;
- : (int * string) list = [(3, "3"); (1, "1")]
```## Build
You need OCaml >= 4.03.0 and dune.
$ make
$ make install## License
The code is free, released under the BSD-2 license.