Felix has been able to do OO for some time, it just isn't sugared. Here's an example:
////////////////// // An OO experiment fun X (var x:int, var y:int) = { proc setx(a:int) { x = a; } proc sety(a:int) { x = a; } fun getx() => x; fun gety () => y; fun sum () => x + y; return (setx=setx, sety=sety, getx=getx, sum=sum); } var a = X(2,3); println$ a.getx(); a.setx(22); println$ a.getx(), a.sum(); var b = a :>> (sum:1->int); proc f(v:(sum:1->int)) { match v with | (sum= ?pp)=> println$ pp(); endmatch; } f b; ///////////// Here, X can be viewed as a constructor for an object. The type of the object is: ( setx:int->void, sety:int->void, getx: unit -> int, gety: unit -> int, sum: unit -> int ) that is, it's a record of functions. Notice that the "data" is 100% encapsulated by the constructor function in this case (but, you could return a pointer if you wanted a variable, or a value if you didn't). Now the line var b = a:>> (sum: 1-> int); is an upcast (coercion) to a type with only the sum field. So we have subclassing based on "forgetting some fields". There's a more anonymous way forget fields using a match. This will work too: match a with | (sum= ?pp)=> println$ pp(); endmatch; you should note that record coercions have nothing to do with objects (coercions and pattern matches work with all records). At present the overloading system requires exact matches so you must explicitly coerce a record to strip fields to match a function taking a record. [It may be possible to relax that]. Clearly, you can easily implement extensions: fun Y(a:X, b:int) { .... } The most important thing to note about this style of OO is that the subtyping notion is NOT based on extension. You can upcast to a "base" consisting of ANY subset of fields without pre-declaring any base types. This is similar to Ocaml's object system and is conceptually VASTLY superior to conventional inheritance: a type with a set of fields Y "isa" X for X with every subset of the fields of Y. I wonder if this is worth sugaring .. -- 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