123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197(**************************************************************************)(* *)(* OCaml *)(* *)(* Simon Cruanes *)(* *)(* Copyright 2017 Institut National de Recherche en Informatique et *)(* en Automatique. *)(* *)(* Raphaël Proust *)(* *)(* Copyright 2022 Nomadic Labs *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)(** {1 Common module signatures}
This compilation unit gathers module signatures which are used in the rest
of the library. Essentially, the rest of the library provides functors to
generate modules with the signatures below.
The Seqes library provides functors to produce specialised variants of the
{!Stdlib.Seq} type where the forcing of an element involves a monad. E.g.,
considering an I/O cooperative scheduling monad à la [Lwt] or [Async], which
we denote with the type ['a io], you can use Seqes to produce the following
type
{[
type 'a t = unit -> 'a node io
and 'a node =
| Nil
| Cons of 'a * 'a t
]}
In addition to specialised types, the library's functor produce an
assortment of functions to operate on values of this type. The assortment of
function is compatible with the {!Stdlib.Seq} (except for the monad part).
See [examples/seqseq/seqseq.ml] for a demonstration of this compatibility.
Familiarity with {!Stdlib.Seq} is assumed. *)(** {1 Two type parameters}
Some monad have two type parameters. E.g., the result monad is over the type
[('a, 'e) result].
The Seqes library offers all the same features over those monads than it
does over the single-parameter monads. Accordingly, below are variants
of the module signatures from {!Sigs1}, but for two-parameter monads.
Note that the specialised type of sequence also carries these two
parameters:
{[
type ('a, 'e) t = unit -> (('a, 'e) node, 'e) io
and ('a, 'e) node =
| Nil
| Cons of 'a * ('a, 'e) t
]}
See [examples/seqres/seqres.ml] for an example of using Seqes for the result
monad. See [examples/seqlwtres/seqlwtres.ml] for an example of using Seqes
for the Lwt+result monad.
{2 Asymmetry}
Note that the two type parameters of the monad are not treated the same.
Seqes only requires a bind for the first parameter but not the second.
{[
val bind : ('a, 'e) t -> ('a -> ('b, 'e) t) -> ('b, 'e) t
]}
*)(** Equivalent to {!Sigs1.SEQMON1TRAVERSORS} but with two type parameters. *)moduletypeSEQMON2TRAVERSORS=sigtype('a,'e)callermontype('a,'e)montype('a,'e)tvaliter:('a->(unit,'e)callermon)->('a,'e)t->(unit,'e)monvalfold_left:('a->'b->('a,'e)callermon)->'a->('b,'e)t->('a,'e)monvaliteri:(int->'a->(unit,'e)callermon)->('a,'e)t->(unit,'e)monvalfold_lefti:('b->int->'a->('b,'e)callermon)->'b->('a,'e)t->('b,'e)monvalfor_all:('a->(bool,'e)callermon)->('a,'e)t->(bool,'e)monvalexists:('a->(bool,'e)callermon)->('a,'e)t->(bool,'e)monvalfind:('a->(bool,'e)callermon)->('a,'e)t->('aoption,'e)monvalfind_map:('a->('boption,'e)callermon)->('a,'e)t->('boption,'e)monvaliter2:('a->'b->(unit,'e)callermon)->('a,'e)t->('b,'e)t->(unit,'e)monvalfold_left2:('a->'b->'c->('a,'e)callermon)->'a->('b,'e)t->('c,'e)t->('a,'e)monvalfor_all2:('a->'b->(bool,'e)callermon)->('a,'e)t->('b,'e)t->(bool,'e)monvalexists2:('a->'b->(bool,'e)callermon)->('a,'e)t->('b,'e)t->(bool,'e)monend(** Equivalent to {!Sigs1.SEQMON1TRANSFORMERS} but with two type parameters. *)moduletypeSEQMON2TRANSFORMERS=sigtype('a,'e)callermontype('a,'e)montype('a,'e)tincludeSEQMON2TRAVERSORSwithtype('a,'e)callermon:=('a,'e)callermonwithtype('a,'e)mon:=('a,'e)monwithtype('a,'e)t:=('a,'e)tvalinit:int->(int->('a,'e)callermon)->('a,'e)tvalunfold:('b->(('a*'b)option,'e)callermon)->'b->('a,'e)tvalforever:(unit->('a,'e)callermon)->('a,'e)tvaliterate:('a->('a,'e)callermon)->'a->('a,'e)tvalmap:('a->('b,'e)callermon)->('a,'e)t->('b,'e)tvalmapi:(int->'a->('b,'e)callermon)->('a,'e)t->('b,'e)tvalfilter:('a->(bool,'e)callermon)->('a,'e)t->('a,'e)tvalfilter_map:('a->('boption,'e)callermon)->('a,'e)t->('b,'e)tvalscan:('b->'a->('b,'e)callermon)->'b->('a,'e)t->('b,'e)tvaltake_while:('a->(bool,'e)callermon)->('a,'e)t->('a,'e)tvaldrop_while:('a->(bool,'e)callermon)->('a,'e)t->('a,'e)tvalgroup:('a->'a->(bool,'e)callermon)->('a,'e)t->(('a,'e)t,'e)tvalmap2:('a->'b->('c,'e)callermon)->('a,'e)t->('b,'e)t->('c,'e)tvalmap_product:('a->'b->('c,'e)callermon)->('a,'e)t->('b,'e)t->('c,'e)tvalpartition_map:('a->(('b,'c)Either.t,'e)callermon)->('a,'e)t->('b,'e)t*('c,'e)tvalpartition:('a->(bool,'e)callermon)->('a,'e)t->('a,'e)t*('a,'e)tend(** Equivalent to {!Sigs1.SEQMON1ALL} but with two type parameters. *)moduletypeSEQMON2ALL=sigtype('a,'e)montype('a,'e)tincludeSEQMON2TRANSFORMERSwithtype('a,'e)mon:=('a,'e)monwithtype('a,'e)callermon:='awithtype('a,'e)t:=('a,'e)tvalis_empty:('a,'e)t->(bool,'e)monvaluncons:('a,'e)t->(('a*('a,'e)t)option,'e)monvallength:('a,'e)t->(int,'e)monvalequal:('a->'b->bool)->('a,'e)t->('b,'e)t->(bool,'e)monvalcompare:('a->'b->int)->('a,'e)t->('b,'e)t->(int,'e)monvalempty:('a,'e)tvalreturn:'a->('a,'e)tvalcons:'a->('a,'e)t->('a,'e)tvalrepeat:'a->('a,'e)tvalcycle:('a,'e)t->('a,'e)tvaltake:int->('a,'e)t->('a,'e)tvaldrop:int->('a,'e)t->('a,'e)tvalmemoize:('a,'e)t->('a,'e)tvalonce:('a,'e)t->('a,'e)tvaltranspose:(('a,'e)t,'e)t->(('a,'e)t,'e)tvalappend:('a,'e)t->('a,'e)t->('a,'e)tvalconcat:(('a,'e)t,'e)t->('a,'e)tvalflat_map:('a->('b,'e)t)->('a,'e)t->('b,'e)tvalconcat_map:('a->('b,'e)t)->('a,'e)t->('b,'e)tvalzip:('a,'e)t->('b,'e)t->(('a*'b),'e)tvalinterleave:('a,'e)t->('a,'e)t->('a,'e)tvalsorted_merge:('a->'a->int)->('a,'e)t->('a,'e)t->('a,'e)tvalproduct:('a,'e)t->('b,'e)t->(('a*'b),'e)tvalunzip:(('a*'b),'e)t->('a,'e)t*('b,'e)tvalsplit:(('a*'b),'e)t->('a,'e)t*('b,'e)tvalof_dispenser:(unit->('aoption,'e)mon)->('a,'e)tvalto_dispenser:('a,'e)t->(unit->('aoption,'e)mon)valints:int->(int,'e)tvalof_seq:'aSeq.t->('a,'e)tend(** Equivalent to {!Sigs1.MONAD} but with two type parameters. *)moduletypeMONAD2=sigtype('a,'e)tvalreturn:'a->('a,'e)tvalbind:('a,'e)t->('a->('b,'e)t)->('b,'e)tend(** Mixed-monad operations *)moduletypeGLUE2=sigtype('a,'e)xtype('a,'e)ftype('a,'e)retvalbind:('a,'e)x->('a->('b,'e)f)->('b,'e)retend(**/**)(* For test purpose we need variants of the monad signatures above where the
type is injective. This makes the GADTs used to model the seq interface
valid.
See https://github.com/ocaml/ocaml/issues/5984 *)moduletypeINJ_MONAD2=sigtype(!'a,'e)tvalreturn:'a->('a,'e)tvalbind:('a,'e)t->('a->('b,'e)t)->('b,'e)tend