module type Enumerable =sig
..end
t
)
of elements (type elt
) in a functional waytype
t
type
elt
type
enum
val start : t -> enum
start c
returns the initial stateval step : enum ->
(elt * enum) option
step st
returns None
when iteration is over,
or Some (e,st')
otherwise, where e
is the next element and
st'
is the next explicit state.
module Interval = struct
type t = { low : int; high : int; } (* Interval (low..high) *)
type elt = int
type enum = { next : int; max : int; }
let start x = { next=x.low; max=x.high; }
let step x =
if x.next > x.max then None
else Some (x.next, { x with next=x.next+1; })
end
module ListMake(E:sig type elt end) = struct
type t = E.elt list
type elt = E.elt
type enum = t
let start xs = xs
let step = function
| [] -> None
| x::xs -> Some (x,xs)
end