data/Sequence

type Name = Meta.Name

type Meta = Meta.Meta

type TreeMeta = { name : Name; level : Meta.Level; size : Nat }

type Exp<Val_> = {#array : [(Exp<Val_>, Meta.Meta)]; #put : (Name, Exp<Val_>); #at : Name; #cons : { head : Exp<Val_>; meta : Exp<Val_>; tail : Exp<Val_> }; #nil; #val : Val_; #streamOfArray : Exp<Val_>; #treeOfStream : Exp<Val_>; #treeOfStreamRec : TreeOfStreamRec<Val_>; #maxOfTree : Exp<Val_>}

type TreeOfStreamRec<Val_> = { parentLevel : ?Nat; stream : Stream<Val_>; subTree : Tree<Val_> }

type Array<Val_> = [(Val<Val_>, Meta.Meta)]

type ArrayStream<Val_> = { array : Array<Val_>; offset : Nat }

type Cons<Val_> = (Val<Val_>, Meta, Val<Val_>)

type Bin<Val_> = { left : Val<Val_>; meta : TreeMeta; right : Val<Val_> }

type Val<Val_> = {#at : Name; #array : Array<Val_>; #arrayStream : ArrayStream<Val_>; #nil; #cons : Cons<Val_>; #bin : Bin<Val_>; #leaf : Val_; #pair : (Val<Val_>, Val<Val_>)}

type Tree<Val_> = {#nil; #bin : Bin<Val_>; #leaf : Val_; #at : Name}

Cartesian trees as balanced representations for sequences.

type Stream<Val_> = {#nil; #cons : Cons<Val_>; #arrayStream : ArrayStream<Val_>}

type SeqType = {#array; #stream; #tree; #pair}

Each sequence representation has a different run-time type, with associated checks for its operations.

type Result<X, Val_> = R.Result<X, Error<Val_>>

Result type for all "meta level" operations returning an X.

type EvalResult<Val_> = Result<Val<Val_>, Val_>

Evaluation results in a Val on success.

type Error<Val_> = {#notOurVal : Val_; #doNotHave : (SeqType, Val<Val_>); #emptySequence; #engineError}

type Ops<Exp_, Val_, Error_> = { valMax : (Val_, Val_) -> R.Result<Val_, Error_>; getVal : Val_ -> ?Val<Val_>; putExp : Exp<Val_> -> Exp_; getExp : Exp_ -> ?Exp<Val_>; putVal : Val<Val_> -> Val_; putError : Error<Val_> -> Error_; getError : Error_ -> ?Error<Val_> }

class Sequence<Val_, Error_, Exp_>(engine : Engine.Engine<Name, Val_, Error_, Exp_>, ops : Ops<Exp_, Val_, Error_>)

public func eval(e : Exp<Val_>) : R.Result<Val_, Error_>

Evaluate expression into a result.

public func haveArray(v : Val<Val_>) : Result<[(Val<Val_>, Meta)], Val_>

Check canonical array forms.

public func haveStream(v : Val<Val_>) : Result<Stream<Val_>, Val_>

Check canonical stream head form.

public func haveTree(v : Val<Val_>) : Result<Tree<Val_>, Val_>

Check canonical tree head form.

public func streamOfArray(v : Val<Val_>) : EvalResult<Val_>

Transforms an array into a stream.

public func treeSize(t : Tree<Val_>) : Nat

number of elms; ignore internal nodes

public func treeLevel(t : Tree<Val_>) : Nat

public func streamNext(s : Stream<Val_>) : ?Cons<Val_>

public func resultPairSplit(r : EvalResult<Val_>) : Result<(Val<Val_>, Val<Val_>), Val_>

public func resultPair(v1 : Val<Val_>, v2 : Val<Val_>) : EvalResult<Val_>

public func treeOfStreamRec(
  parentLevel : ?Nat,
  s : Stream<Val_>,
  tree : Tree<Val_>
) : EvalResult<Val_>

Transforms a stream into a tree.

public func treeOfStream(s : Val<Val_>) : EvalResult<Val_>

Transforms a stream into a tree.