On 02/03/2013, at 5:30 PM, Michael Maul wrote:

> So :>> does specificly what? and what other operators affect record types?

( a ;>> t)

is a generic coercion. Roughly it's supposed to be "a safe cast".

In this case, technically, it's nothing more than a multi-field projection.

In fact, if you interpret 

 typedef V3 = (x:int, y:int, z:int);

as the usual three dimensional space, and

        typedef V2 = (x:int, y:int);

as the ground, then coercion from a value of type V3 to V2 is 
the "shadow" of the three dimensional space at noon on the
ground.

You can also pattern match on records, and you can leave fields out of the 
patterns,
for example:

  println$ 
        match v3' with
        | (z=?z) => z
        endmatch
  ;

Records differ from structs in that the order of the fields does not matter,
and also they're structurally typed (which is why a typedef was used:
its just an alias).

Unlike tuples, however, there's no builtin or library function to
convert to a string and no equality operator.

FYI: Felix sorts record fields into alphabetical order so the types
are easy to check.

Note that a tuple is basically a record with fields named 
in Felix as 0 1 2 3 .. etc.

You can also "chop the end off tuples" with a coercion although the compiler
complains:

var x = 1, 2.1, "hi";
println$ (x :>> (int * double));

~/felix>flx b
WARNING: Wrong type in coercion src value 
x<42895> has type int * double * string
coercion to int * double not supported

(1, 2.1)

This is because it doesn't work if the result is a compact linear type.
At present if you use a bad coercion you get a diagnostic like above,
BUT, the coercion is done anyhow, using a reinterpret_cast<>.
So on your head be it.

The main use of coercions is for compact linear types and arrays:

        T ^ 3 ^ 4  ==> T ^ (4 * 3)

which converts an array of arrays into an array indexed by a tuple.
Another coercion goes:

        4 * 3  ==> int

which is a bit nasty (it should be to 12) which allows you to 
access the array of arrays as a linear array.

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




------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to