Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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.