So here's array optimised is2path function:

fun ix2path (t:typecode) (ix:int) : path =
{
  fun aux (t:typecode) (var ix:int) (p:path) : path =
  {
    match t,ix with
    | Primitive _, 0 => return rev p;
    | Array (?n,?t0),_ =>
      var sz = pcount t0;
      var choice = ix / sz;
      assert choice < n;
      ix -= choice * sz;
      assert ix < sz;
      return aux t0 ix (Cons ((Choice choice), p));

    | _ =>
      choice = 0;
      var t0 = subcomponent t choice;
      sz = pcount t0;
      while ix >= sz do 
        ++choice;
        t0 = subcomponent t choice;
        ix -= sz;
        sz = pcount t0;
      done
      return aux t0 ix (Cons ((Choice choice), p));
    endmatch;
  }
  return aux t ix Empty[selector];
}

But now more serious stuff. So far, we can only describe structure
imposed on a flat object. 

We want implementations which copy, move, destroy, assign these objects 
(or subobjects thereof). It's clear how this will work: we flatten out the 
"tree"
structure to a tuple of primitives, and just call the primitive copy, move, 
destroy,
assign functions in sequence. The function that does that will itself be he
copy, move, destroy or assign function for the top level type.

I want to point out this dynamic polymorphism exceeds the capabilities
of most functional programming languages. Languages like Ocaml
use boxing, so a polymorphic function can manipulate all objects
equally, irrespective of type, because all types fit in a box.
[In Ocaml a boxed type is either an integer or a pointer, one bit is
used to determine which. So ints are 2^63 on a 64 bit machine.
Pointers don't care about losing a bit because they're always aligned
to multiple of 16].

With the proposed dynamic typing, polymorphic functions can
actually manipulate objects directly. The have to be on the heap though
(alloca doesn't sound much fun :)

Anyhow before doing this we need to extend the representation to handle
two more things.

First, we need Pointer t. A pointer to a t obviously. We have to mark these,
so the GC can find pointers. Also a Pointer isn't a primitive, its a structural
combinator (like tuple and array formation). Without pointers we cannot
describe lists.

The second thing we need .. thinking of lists again .. is variants.
Next email for that!

--
john skaller
skal...@users.sourceforge.net
http://felix-lang.org




------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to