You can now do this:

////
struct X {
  a:int;
  b:double;
  fun f (x:int) => self.a + x + x;
  fun g  => self.a;
};

var x : X = X (1,2.0);
println$ x.a, x.b, f x 42, g x;
println$ x.a, x.b, x.f 42, x.g;
////

At present:

* Polymorphism isn't supported.
  (coming)

* It must be a Felix function (not a C binding)
  and not a callback

* ctor's work but they construct their name type
  FROM the object, they don't construct the object type
  (it's consistent, but "ctor" is actually a value conversion
   and NOT a constructor: poor choice of name perhaps)

* The self argument is passed by "val"ue

* therefore procedures can't modify the object
  (coming)

* It should work for a cstruct too.

It isn't clear what a generator should do (pass by value or pointer?)
It should work at present with the object as an ordinary value.

Note: this feature does not introduce any new semantics.
The functions are NOT scoped inside the struct, despite appearances.

It's exactly equivalent to write a function with an argument of the struct
type named self in the scope containing the struct definition.
Indeed, this is precisely how it is implement in the parser.

Therefore, take care when writing functions accepting a value of the
struct type explicitly, since these live in the same scope as the
functions inside the struct.

Note: closures of these function over (monomorphised specialisations of) 
the object exist trivially by the usual partial application. Nothing new here.
but it looks sexy.

val h = x.f;
println$ h 42;



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




------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to