On 10/1/07, skaller <[EMAIL PROTECTED]> wrote: > Anyhow, I think (LOL!) it works like this: here is println: > > proc println[T with Str[T]] (x:T) { > fprint (cout, str x); > endl cout; > }; > > > Now, println itself is 'opening Str[T]' for ALL T. > For this to work, Str must be in scope, but that is all. > This function is implemented (literally) as: > > proc println[T] (x:T) { > open Str[T]; > fprint (cout, str x); > endl cout; > }; > > so you can see, it really DOES open Str, for all values of T > it is called with. That's all that 'with Str[T]' does: it opens > Str[T] in the scope of the function. [More precisely, > it opens it BEFORE the parameter list, otherwise 'open' > in the body would be good enough .. but then, in case you > didn't know, Felix binds parameters in the SAME scope as > the function body.. hehe!]
Oh that makes perfect sense. Thanks again. /me goes back to misunderstanding things :) So this is really interesting, I always thought instances had to be at the top level, but this works: module Foo { union foo = Bar | Baz; instance Str[foo] { fun str: foo -> string = | Bar => "Bar1" | Baz => "Baz1"; } } module Foo2 { union foo = Bar | Baz; instance Str[foo] { fun str: foo -> string = | Bar => "Bar2" | Baz => "Baz2"; } } open module Foo3 { union foo = Bar | Baz; instance Str[foo] { fun str: foo -> string = | Bar => "Bar3" | Baz => "Baz3"; } } 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. (The str call shouldn't be relying on the same functionality that's used in println, right?) What do you think about starting to migrate the instances into the modules for things like list, varray, and etc? ------------------------------------------------------------------------- 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