123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110(******************************************************************************)(* *)(* Feat *)(* *)(* François Pottier, Inria Paris *)(* *)(* Copyright Inria. All rights reserved. This file is distributed under the *)(* terms of the MIT license, as described in the file LICENSE. *)(******************************************************************************)(**A signature for implicit finite sequences.
These sequences are implicit, which means that they are not explicitly
represented in memory as actual sequences of elements; instead, they are
described by a data structure which contains enough information to produce
an arbitrary element upon request. This design decision imposes some
constraints on the operations that can be efficiently supported; for
instance, [filter] is not supported.
This signature forms an applicative functor. *)moduletypeIFSEQ_BASIC=sig(**['a seq] is the type of sequences whose elements have type ['a]. *)type'aseq(**Constructors. *)(**[empty] is a sequence of length zero. *)valempty:'aseq(**[zero] is a synonym for [empty]. *)valzero:'aseq(**[singleton x] is a sequence of length one whose single element is [x]. *)valsingleton:'a->'aseq(**[one] is a synonym for [singleton]. *)valone:'a->'aseq(**[rev xs] is the reverse of the sequence [xs]. *)valrev:'aseq->'aseq(**[sum s1 s2] is the concatenation of the sequences [s1] and [s2]. *)valsum:'aseq->'aseq->'aseq(**[(++)] is a synonym for [sum]. *)val(++):'aseq->'aseq->'aseq(**[product s1 s2] is the Cartesian product of the sequences [s1] and [s2].
Its length is the product of the lengths of [s1] and [s2]. The first pair
component is considered most significant. *)valproduct:'aseq->'bseq->('a*'b)seq(**[( ** )] is a synonym for [product]. *)val(**):'aseq->'bseq->('a*'b)seq(**[map phi s] is the image of the sequence [s] through the function [phi].
If the user wishes to work with sequences of pairwise distinct elements,
then [phi] should be injective. If furthermore the user wishes to work
with sequences that enumerate all elements of a type, then [phi] should
be surjective. *)valmap:('a->'b)->'aseq->'bseq(**[up i j] is the sequence of the integers from [i] included up to [j]
excluded. *)valup:int->int->intseq(* Observations. *)(**The type [index] is the type of integers used to represent indices and
lengths. *)typeindex(**[length s] is the length of the sequence [s]. *)vallength:'aseq->index(**[get s i] is the [i]-th element of the sequence [s]. The index [i] must
be comprised between zero included and [length s] excluded. *)valget:'aseq->index->'a(**[foreach s k] iterates over all elements of the sequence [s]. Each
element in turn is passed to the loop body [k]. *)valforeach:'aseq->('a->unit)->unit(**[to_seq s k] produces an explicit representation of the sequence [s] as a
sequence in the sense of OCaml's standard library module [Seq]. This
sequence is prepended in front of the existing sequence [k]. *)valto_seq:'aseq->'aSeq.t->'aSeq.tend(**This signature extends {!IFSEQ_BASIC} with more operations. *)moduletypeIFSEQ_EXTENDED=sigincludeIFSEQ_BASIC(**Iterated sum. *)valbigsum:'aseqlist->'aseq(**Indexed iterated sum. *)valexists:'alist->('a->'bseq)->'bseq(**[sample m s k] is an explicit sequence of at most [m] elements extracted
out of the implicit sequence [s], prepended in front of the existing
sequence [k]. If [length s] is at most [m], then all elements of [s] are
produced. Otherwise, a random sample of [m] elements extracted out of [s]
is produced. *)valsample:int->'aseq->'aSeq.t->'aSeq.tend