#line 26 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
  Array as Value (immutable).
  class ArrayValue[t,v]
  {
  #line 33 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    Length.
    virtual fun len: t -> size;
  
  #line 40 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    Unchecked common indexing.
    virtual fun unsafe_get: t * size -> v;
  #line 44 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    Checked common indexing.
    fun get[I in ints] (x:t, i:I) = {
      assert i.size < x.len;
      return unsafe_get (x,i.size);
    }
  #line 68 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
  
     Checked common indexing.
    fun apply [I in ints] (i:I, x:t) => get (x,i.size);
  
  #line 74 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    Callback based value iterator.
    virtual proc iter (_f:v->void) (x:t) {
      val n = x.len;
      if n > 0uz do
        for var i:size in 0uz upto n - 1uz do
          _f$ unsafe_get(x,i);
        done
      done
    }
  
  #line 86 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    Callback based index and value iterator.
    Callback f index value.
    virtual proc iiter (_f:size -> v->void) (x:t) {
      val n = x.len;
      if n > 0uz do
        for var i:size in 0uz upto n - 1uz do
          _f i  (x,i).unsafe_get;
        done
      done
    }
  
  #line 110 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    instance Iterable[t,v] {
      Stream  value iterator.
      gen iterator(xs:t) () : opt[v] =
      {
        if xs.len > 0uz do
          for var j in 0uz upto xs.len - 1uz do
            yield Some (xs,j).unsafe_get;
          done
        done
        return None[v];
      }
    }
  
    inherit Streamable[t,v];
  #line 128 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    Traditional left fold.
    virtual fun fold_left[u] (_f:u->v->u) (init:u) (x:t): u = {
      var o = init;
      val n = x.len;
      if n > 0uz do
        for var i:size in 0uz upto n - 1uz do
          o = _f o (unsafe_get(x,i));
        done
      done
      return o;
    }
  
  #line 144 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
  Traditional right fold.
    virtual fun fold_right[u] (_f:v->u->u) (x:t) (init:u): u = {
      var o = init;
      val n = x.len;
      if n > 0uz do
        for var i:size in n - 1uz downto 0uz do
          o = _f (unsafe_get(x,i)) o;
        done
      done
      return o;
    }
  
  #line 165 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    virtual fun fold[u] (_f:u->v->u) (init:u) (x:t): u =>
      fold_left _f init x
    ;
  #line 173 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    Membership by predicate.
    virtual fun mem(pred:v->bool) (x:t): bool = {
      val n = x.len;
      if n > 0uz do
        for var i:size in 0uz upto n  - 1uz do
          if pred(unsafe_get(x,i)) do
            return true;
          done
        done
      done
      return false;
    }
  
  #line 192 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    Membership by relation to given value.
    virtual fun mem[u] (rel:v*u->bool) (x:t) (e:u): bool =>
      mem (fun (i:v) => rel(i, e)) x
    ;
  
  #line 201 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    Array as Set:
    Membership by equality of value type.
    instance[with Eq[v]] Set[t,v] {
      fun \(\in\) (elt:v, a:t) => mem eq of (v * v) a elt;
    }
    inherit[t,v with Eq[v]] Set[t,v];
  
  #line 212 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    Searching for value satisfying predicate.
    virtual fun find(pred:v->bool) (x:t): opt[v] = {
      val n = x.len;
      if  n > 0uz do
        for var i:size in 0uz upto n - 1uz do
          if pred(unsafe_get(x,i)) do
            return Some$ unsafe_get(x,i);
          done
        done
      done
      return None[v];
    }
  
  #line 229 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    Searching for value satisfying relation to given value.
    virtual fun find (rel:v*v->bool) (x:t) (e:v): opt[v] = {
      val n = x.len;
      if n > 0uz do
        for var i:size in 0uz upto n - 1uz do
          if rel(unsafe_get (x,i), e) do
            return Some$ unsafe_get (x,i);
          done
        done
      done
  
      return None[v];
    }
  
  #line 245 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    fun \(\sum\) [with FloatAddgrp[v]] (it:t) =
    {
      var init = #zero[v];
      for v in it do init = init + v; done
      return init;
    }
  
  #line 254 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    fun \(\prod\)[with FloatMultSemi1[v]] (it:t) =
    {
      var init = #one[v];
      for v in it do init = init * v; done
      return init;
    }
  
  
  #line 268 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
  }
  
  #line 279 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
  
  class TrueArrayValue [t,x,v]
  {
     inherit ArrayValue[t,v];
     virtual fun render : x -> size;
     fun true_unsafe_get (a:t, i:x) => unsafe_get (a, render i);
  }
  
  #line 293 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
  Array as Object (mutable).
  class ArrayObject[t,v]
  {
    inherit ArrayValue[t,v];
  
  #line 302 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    // Unsafe store value into array by common index.
    virtual proc unsafe_set: t * size * v;
  
  #line 311 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    virtual fun unsafe_get_ref : t * size -> &v;
  
  #line 317 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    // Checked store value into array by common index.
    proc set[I in ints] (x:t, i:I, a:v) {
      assert i.size < x.len; unsafe_set (x,i.size,a);
    }
  
  #line 324 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    fun n"&." [I in ints] (x:t, i:I) : &v = {
      assert i.size < x.len;
      return unsafe_get_ref (x,i.size);
    }
  }
  
  #line 334 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
  class TrueArrayObject[t,x, v]
  {
    inherit TrueArrayValue[t,x,v];
    inherit ArrayObject[t,v];
    proc true_unsafe_set(a:t, i:x, e:v) => unsafe_set (a, render i, e);
  }
  
  #line 353 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
  Array as Contiguous STL Object.
  Provides STL iterators type +v
  class ContiguousArrayObject[t,v]
  {
    inherit ArrayObject[t,v];
  
  #line 361 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    Start of array iterator.
    virtual fun stl_begin: t -> +v;
  
    One past the end of array iterator.
    virtual fun stl_end: t -> +v;
  
  #line 371 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    Add integer to iterator.
    fun + [I in ints] (pa:t, i:I) : carray [v] = {
       assert i.size < pa.len;
       return pa.stl_begin + i.size;
    }
  
  #line 382 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    In place sort using STL sort with Felix comparator.
    proc sort (cmp: v * v -> bool) (a:t) {
      var first = a.stl_begin;
      var last = a.stl_end;
      var z = Sort::stl_comparator (cmp);
      Sort::stl_sort (z,first,last);
    }
  
  #line 393 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
    In place sort using STL sort with default comparison.
    proc sort[with Tord[v]] (a:t) => sort (< of (v*v)) a;
  
  }
  
  #line 402 "/home/travis/build/felix-lang/felix/src/packages/arrays.fdoc"
  class TrueContiguousArrayObject[t,x, v]
  {
    inherit TrueArrayObject [t,x,v];
    inherit ContiguousArrayObject[t,v];
    fun + (pa:t, i:x) : carray [v] => pa + render i;
  }