On 22/07/2012, at 4:40 PM, Dobes Vandermeer wrote: > On Fri, Jul 20, 2012 at 10:51 PM, john skaller > <skal...@users.sourceforge.net> wrote: > The problem isn't unique to size 1, and it affects C++ too > > fun f(x: T * T) => ... > fun f(x:T, y: size) => ... > f (1.size, 2.size) > > with T -> size both signatures match. > > Hmm most of this discussion is over my head, but I have to admit that this > particular problem seems potentially confusing ... however, I had previously > thought "I wonder how one can capture their arguments and pass them all > unaltered to another function" and my resulting thought was "declare a single > parameter of a tuple type and pass that".
You can't do anything else. If you write a function fun f(x:int, y:double) => x.double + y; this is *exactly* the same as the function fun f( a: int * double ) => a.0.double + a.1; The only difference is that first function does a "free" pattern match for you to name the components. You can see this: var x = 1, 2.0; println$ x; will work with both versions of f. > > i.e. something like this might be possible: > > fun logging_proxy[T,R](x:T, f:T->R) : R = { > res := f T; > println str(f) + " returns " + str(res); > return res; > } // I'm getting a mysterious error on this one: Expected declaration of > typed entity for index 31039, got T (1) you meant f x not f T (2) Missing "$" after println. The grammar parses your call like this: ((println str) f) + "returns" + (str res) which is not what you meant. $ is a binary forward application operator with low precedence. BTW: it's a good idea to stop writing f (x) like in C. The parens there have no effect. You may be confused that they're a "call operator" and think something like str (f) has a high binding because of the call. But it's the same as str f Of course you need parens for grouping: f (1,2) since f 1,2 means (f 1), 2 > > fun f(a:int,b:int) => a * b; > f2 := logging_proxy[int*int,int](f); > f2(3,4); > > This is kind of like aspect-oriented programming, it can be useful for > certain kinds of re-usable functionality that wrap functions. > > Hopefully that's helpful or interesting in some way .. > Be aware Felix doesn't "really" support polymorphic function closures or variables. Also note that in a class with type variables you cannot have variables at all. The workaround is a function: fun one () => 1; which can be used like: #one // means the same as one () but prettier You can do that in a module (because they can't be polymorphic and variables don't inherit the type variables). the reason is .. ah .. mm .. laziness. I mean *mine* not the functional programming kind :) To have variables, I would have to have an initialisation routine for every instance of a class. Classes get an initialisation routine, if and only if they're monomorphic (no type variables). [It's a bit of a pain, I just ran into that restriction myself :] -- john skaller skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language