And now we have polymorphism.. /////// struct X[t] { a:int; b:double; c:t; fun f (x:int) => self.a + x + x; fun g => self.a; proc s (x:int) => self.a = x; fun cc => self.c,self.c; fun cx[u] (q:u) => self.c,q; };
var x = X (1,2.0, "Hi"); println$ x.a, x.b, f x 42, g x; println$ x.a, x.b, x.f 42, x.g; &x.s 5; println$ x.a, x.b, x.f 42, x.g; println x.cc; println$ x.cx 99.2; /////// ~/felix>flx --test=build/release --force st (1, 2, 85, 1) (1, 2, 85, 1) (5, 2, 89, 5) (Hi, Hi) (Hi, 99.2) //////////// Note that: * the type of x is deduced from the constructor as X[string] * the function cx is polymorphic in its own right, as well as being applied to a polymorphic struct * the last case would only work since I fixed deduction for multiple arguments! Unfortunately: var closure = x.cx[string, double]; Felix only allows you to elide trailing type variables during deduction. Here, we know the type of the first type variable is string since cx is applied to x. But we have to specify the type of the second variable "u" as double since there's no argument at this point. We'd rather leave out the first type variable's spec here since it is known but we can't. This is a typical of Felix higher order functions: the types are usually listed in the order they're needed for arguments, which is the reverse order we actually need since arguments are partially applied from left to right but type variables can only be dropped from right to left. Still .. it's a minor nit! -- 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