Here's quick demo of compact linear types.

///////////////////

var bits = false, false, false, false, false;
proc p() {
  for var i in 0 upto 4 do
    println$ bits . i;
  done
}

p;
bits . 0 = true;
p;
println$ C_hack:: sizeof [typeof bits];

var j = bits :>> int;
println$ j;
var k = j :>> (2^5);
println$ k;

////////////////
false
false
false
false
false
true
false
false
false
false
4
16
(true, false, false, false, false)
//////////////


The first code makes an array of 4 bools. Remember bool = 2.
And false = case 0 of 2, true = case 1 of 2.

The first 5 prints show we can index this array.

Next, we set the high bit, which is numbered 0, to true.
And print again, to make sure it worked.

Next we prrint the size of the array. Note it is 4.
This is the size of an int on my box.

Now we convert to an int, to get the compact linear value,
which is 16 of course: 2^4. And convert back to a bit array
and print it again.

The status at the moment is that 

(a) compact linear types are stored in an int

(b) there is no check that a compact linear type is small enough

(c) the allowed coercions are to and from an int, plus some others,
needs to be examined. 

The size constraint for compact linear types is justified on the grounds that
the primary purpose is to be array indices. We don't need huge array indicies
because no one has enough memory to need them. The coercions on
array indicies represent changes in the array shape.

One of the simpler goals here, however, is to get a type:

        uint[N]

which is an unsigned int of N bits. There's a bit of a challenge making
that work for larger N. Ocaml ints are only 31 bits, using Big_int gets around
that but is a real PITA. 

Of course the point is that bitwise operations can then be implemented
with a loop up to N. Of course this isn't efficient, so we'd use a typeclass
and specialise it for 8,16,32,64. And then there's a challenge to go further
and represent, say, uint[24] by the next larger machine word (transparently).

For the moment, what we have is a big advance over C. We can get and set
a bit with a numerical index, without using any shifts and masks. 

Note also, this will just work for trits as well! I will show some really cool 
stuff
in the next post.

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




------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. 
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to