package seqes

  1. Overview
  2. Docs
Seq with monads

Install

Dune Dependency

Authors

Maintainers

Sources

seqes-0.1.tar.gz
md5=d3fdbbc3fca033015f2c6cb9fdaba133
sha512=1aa757c85b67f96e77c82c905eb0ba930ce4284e4c46551525421b77bf458b5993b8d63fd68ed54df95f6a03d8ce7bb60e20ca517bfa77f85d0d7267fbe35cb4

Description

Variations of the Seq module with monads folded into the type

Tags

monad seq

Published: 12 Dec 2022

README

Seqes

A library to compose the abstraction of the Stdlib.Seq module with monads.

The Stdlib.Seq module doesn't allow mixing in monads. Specifically, the Stdlib.Seq module provides the following type definition:

type 'a t = unit -> 'a node
and +'a node =
  | Nil
  | Cons of 'a * 'a t

in which an 'a Seq.t must be a simple lambda returning a node. You cannot thread that lambda into a monad.

The Seqes library provides functors to generate new Seq-like modules, adapted to your monad.

Seqes.Standard

The functor Seqes.Standard.Make1 takes a monad parameter.

module SeqM = Seqes.Standard.Make1(Monad)

It returns a module containing traversors using the provided Monad.

SeqM.iter : ('a -> unit Monad.t) -> 'a Stdlib.Seq.t -> unit Monad.t

Check examples/seqlwt/seqlwt.ml for an example use of Seqes.Standard.Make1.

Seqes.Monadic.Make1

The functor Seqes.Monadic.Make1 takes a monad parameter.

module SeqM = Seqes.Monadic.Make1(Monad)

It returns a module with a fresh type definition integrating the Seq abstraction and the monad together:

type 'a t = unit -> 'a node Monad.t
and 'a node =
  | Nil
  | Cons of 'a * 'a t

It also exports all the functions from the Stdlib.Seq module but operating on that new type instead.

SeqM.iter : ('a -> unit) -> 'a SeqM.t -> unit Monad.t

The library provides more advance usage. Specifically, note how the SeqM.iter function takes a function 'a -> unit, and how it is sometimes useful to pass a 'a -> unit Monad.t function instead.

The module produce by Seqes.Monadic.Make1 actually contains a submodule M with those specialised variants.

SeqM.M.iter : ('a -> unit Monad.t) -> 'a SeqM.t -> unit Monad.t

In addition to this submodule M, the module contains two functors to generate more specialised sets of functions. See examples/seqlist/ for an example of this even more advanced use.

Seqes.Standard.Make2 and Seqes.Monadic.Make2

If your monad has two type parameters (e.g., ('a, 'e) result), then you can use Seqes.Standard.Make2 and Seqes.Monadic.Make2 instead of the functors mentioned above.

See examples/seqres/seqres.ml and examples/seqlwtres/seqlwtres.ml for examples.

Dependencies (2)

  1. dune >= "3.0"
  2. ocaml >= "4.14"

Dev Dependencies (5)

  1. odoc with-doc
  2. ppx_expect with-test
  3. alcotest with-test & >= "1.5.0"
  4. qcheck-alcotest with-test
  5. qcheck with-test & >= "0.19"

Used by

None

Conflicts

None

OCaml

Innovation. Community. Security.