package bam

  1. Overview
  2. Docs

A forest can be considered as a non-empty sequence of trees. The functions declared in this module transposed naturally the functions provided on tree.

Function of this modules always ensure that the sequence is not empty. This is why the function sequence takes two arguments instead of one.

Because of the non-emptiness property, the function first is total.

Names of those functions are inspired from Haskell.

type 'a t

Datatype for a forest.

val lift : 'a tree -> 'a t

lift tree returns a forest made of a single tree.

val make : 'a -> ('a -> 'a Seq.t) -> 'a t

make root produces a forest with a single tree by using make

val uncons : 'a t -> 'a tree * 'a tree Seq.t

uncons forest splits the forest into a tree and a sequence of trees.

val sequence : 'a t -> 'a t Seq.t -> 'a t

seqnece tree forest returns a new forest made of a sequence of forest, namely Seq.cons tree forest |> Seq.concat.

val map : ('a -> 'b) -> 'a t -> 'b t

map f forest applies a function f over each value of the forest.

val map_tree : ('a tree -> 'b tree) -> 'a t -> 'b t

map_tree f forest applies a function f over each tree of the forest.

val crunch : int -> 'a t -> 'a t

crunch i forest is the analogue of crunch

A monadic interface

val return : 'a -> 'a t

return v returns a forest made of a single value.

val bind : 'a t -> ('a -> 'b t) -> 'b t

bind forest f is a generalisation of bind over sequence of trees.

module Syntax : sig ... end

Monadic operators.

OCaml

Innovation. Community. Security.