On 17/01/2013, at 4:43 AM, Dobes Vandermeer wrote:

> In Felix you can do this:
> fun f(i:int) =>
>   let ?g = fun (x:int) => i + x in
>   g (i+2)
> ;
> but this is not the same: it makes g a closure. Closure can only
> be inlined away with data flow analysis, it may happen in this case
> but I wouldn't bet on it :)
> 
> There's no need to make bets, just try it out and look at the disassembly to 
> see what happens with your preferred compilers.

Ah, I'm talking about the Felix compiler flxg.

> 
> In CoffeeScript they only have the lambda syntax for definition functions; 
> i.e. they have f = fun (x) => x*x and NOT fun f(x) => x*x.  This works 
> surprisingly well and keeps the language nice and simple - now there's just 
> one function construct to support, and at little cost (basically just the 
> extra " = " in terms of character count; it's no harder to read, and its 
> trivial for the compiler to assign a name to the function when appropriate).
> 
> You could do the same transform - just treat val g = fun(x) => x*x as if they 
> had typed fun g(x) => x*x .

Actually no, I can't. The reason is, functions bound by name like

        fun f(x:int)=> x;

can be overloaded on the name. Variables like:

        val f = fun (x:int) => x;

cannot be overloaded. The semantics in both cases are probably the same
(modulo the weirdness we have previously discussed) after binding though.

There's a second reason this cannot be done in general: polymorphism.
In a fun binder like:

        fun f[T] (x:T) => x;

f is polymorphic. You cannot do this:

        val f[T] = fun(x:T) => x;

or whatever the syntax would be, because that would denote
a polymorphic closure. Felix does not allow polymorphic objects.
[Boxed ones might be supported, but they're not at this time]



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




------------------------------------------------------------------------------
Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
and much more. Keep your Java skills current with LearnJavaNow -
200+ hours of step-by-step video tutorials by Java experts.
SALE $49.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122612 
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to