On Wed, 2007-03-21 at 21:01 +0100, Rhythmic Fistman wrote:
> How do I make a record/struct in felix?

//////////////////////////////////////////
#import <flx.flxh>

// struct
struct X { x: int; y:int; }
val a = X(1,2);
print$ f"(%d,%d)\n" (a.x, a.y);

//record
val b = struct { x=1; y=2; };
print$ f"(%d,%d)\n" (a.x, a.y);

// record type:
typedef b_t = struct {x:int; y:int; };
typedef x_t = struct {x:int; };

// record coercion
val x = b:x_t; // discards y

// record pattern match (I think .. :)
match b with
| struct { x=?x; } => { print x; endl; }
endmatch;
////////////////////////////////////

The ugly use of 'struct' everywhere for records is just because
I cant think of a cool notation. Ocaml uses { .. } for records,
but Felix uses that for anon functions/procedures with unit argument.

You can't pattern match structs. 

Tuples and records are structurally typed, records using
names for the projection functinos, tuples using numbers.

Structs are nominally typed.

Classes are also nominally typed structs with methods
thrown in.

ALL 4 of these products are implemented with plain old C++
structs.

Modules are also products, effectively C++ classes with
all static members, or, just a C++ namespace.

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to