I have been wondering about the following problem: ////////////// open class Y { type INT = "int"; ctor INT: int = "$1"; instance Eq[INT] { fun == : INT * INT -> bool = "$1==$2"; } } open Eq[INT];
var a = INT 1; var b = INT 2; println$ a == b; /////////// This works fine. But now consider this one: //////////////// header "enum X {A,B,C};"; cenum X = A,B,C; println$ A == B; ////////////////// I have just implemented "cenum" in response to the hugely ugly problem: type X = "X"; const A:X = "A"; const B:X = "B"; const C:X = "C"; It's long winded, the cenum is better. But I want to go further: since these are C enumerations, they're just integers. So we should at least be able to compare them. This is implemented too, but the comparison is just like: fun == : X * X -> bool = "$1*$2"; There's nothing wrong with this definition, the problem is that it isn't an instance of Eq, so there's no virtual dispatch. Ok so lets suppose I generate this: instance Eq[X] { fun == : X * X -> bool = "$1*$2"; } Now we have the dispatch. Of course we have to open Eq[X]; But what happens if the definitions are in a class C? No problem if we write the open Eq[C::X] after the class .. the problem is that the code generator (Scheme code) is in the parser, and it can only put code locally. If we just emit open Eq[X] inside the class, it is all fine inside the class .. but the view will not be visible outside the class C even if we open the class C. class C { type X = "X"; open Eq[X]; } open C; We can't see the == operator here, only in the class C. SOLUTION: inherit Eq[X]; Lol. Does the same as open except it also exports the view (when C is open, or itself inherited). The effect of this is profound. The whole standard library is wrong: I regularly open all the classes like Eq, Str etc in global scope to expose them (even if the class itself is not open by default). -- john skaller skal...@users.sourceforge.net ------------------------------------------------------------------------------ Keep Your Developer Skills Current with LearnDevNow! 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-d2d _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language