On Mon, 2007-10-01 at 17:58 -0700, Erick Tryzelaar wrote: > On 10/1/07, skaller <[EMAIL PROTECTED]> wrote:
> /me goes back to misunderstanding things :) My turn next .. been reading the Ruby docs .. so I can understand your weird (1,2,3).foreach { |i| print i } stuff. Well, the doc explains this isn't what I thought it was: in fact, the LHS and RHS are coroutines. So actually, what you wanted to do is better described by the idea that |i| is a channel, and the LHS and RHS are fthreads/fibres. > So this is really interesting, I always thought instances had to be at > the top level, but this works: [] Indeed: the only requirement is that the typeclass (and of course the instance types) are visible. > println $ str Foo::Bar; > println $ str Foo2::Bar; > println $ str Bar; > > which prints: > > Bar1 > Bar2 > Bar3 > > You don't even have to open the instance of Foo3 to get it to work. No, you only need to open Str, the typeclass. If the method str has type T, the type of the typeclass, lookup will work for any type T, even if there is no instance. If there is no instance, it will fail later during instantiation. Be aware of the gotcha: str (1,2,3,4,5) works fine but str (1,2.0,"Three",4ul) fails. The first one works by a fluke .. the argument is NOT a tuple .. its an array. It's not possible to define str to work on an arbitrary tuple at the moment. What's more, you can't even define it on a pair, because if you do then str (1,2) will be ambiguous between the array and pair implementations ;( However I think I have finally found how to fix the problem. What you want is to handle tuple like a list, but at compile time. (Run time is possible later when the RTTI is souped up to dynamic typing language standards). To do that, you need a way to iterate something over the tuple. I tried flatten and other things but here is the go: pile_right : t1 * t2 * t3 ... tn -> t1 * (t2 * (t3 * .. (tn * ()))) ..))) Every element is a pair of a single type on the LHS, and another pair on the RHS, except the sentinel (). Which is clearly a list and will allow recursion like: fun str[T with piled[T]] = | ?h, ?t => str h + ", " str t | () => "" ; where the call 'str t' above is polymorphically recursive (calls the same function but with different type arguments). -- John Skaller <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language