package seqes

  1. Overview
  2. Docs

Traversors

A traversor is a function that traverses a sequence, applying a caller-provided function on the sequence's elements. E.g., iter.

A traversor may traverse only a portion of the sequence. E.g., for_all.

The type of traversor mentions two distinct monad types:

  • 'a mon: the monad that the sequence is specialised to
  • 'a callermon: the monad that the caller-provided functions use

These two monad types can be different. The main use for these types being distinct is to provide both plain-traversors (e.g., the plain-iter has type ('a -> unit) -> 'a t -> unit mon) and mon-traversors (e.g., the mon-iter has type ('a -> unit mon) -> 'a t -> unit mon). Plain-traversors are obtained with type 'a callermon := 'a whereas mon-traversors are obtained with type 'a callermon := 'a mon.

There are more advanced use for tiers of monads. See examples/seqlist/seqlist.ml for an advanced example involving List and Option.

type 'a callermon

callermon is the type constructor for the monad used in caller-provided functions.

The type is meant to be substituted by the functor that produces modules following this signature.

type 'a mon

mon is the type constructor for the monad used in the sequence.

The type is meant to be substituted by the functor that produces modules of following this signature.

type 'a t

t is the type constructor for the sequence.

The type is meant to be substituted by the functor that produces modules of following this signature.

val iter : ('a -> unit callermon) -> 'a t -> unit mon
val fold_left : ('a -> 'b -> 'a callermon) -> 'a -> 'b t -> 'a mon
val iteri : (int -> 'a -> unit callermon) -> 'a t -> unit mon
val fold_lefti : ('b -> int -> 'a -> 'b callermon) -> 'b -> 'a t -> 'b mon
val for_all : ('a -> bool callermon) -> 'a t -> bool mon
val exists : ('a -> bool callermon) -> 'a t -> bool mon
val find : ('a -> bool callermon) -> 'a t -> 'a option mon
val find_map : ('a -> 'b option callermon) -> 'a t -> 'b option mon
val iter2 : ('a -> 'b -> unit callermon) -> 'a t -> 'b t -> unit mon
val fold_left2 : ('a -> 'b -> 'c -> 'a callermon) -> 'a -> 'b t -> 'c t -> 'a mon
val for_all2 : ('a -> 'b -> bool callermon) -> 'a t -> 'b t -> bool mon
val exists2 : ('a -> 'b -> bool callermon) -> 'a t -> 'b t -> bool mon