I am about to commit a new version of Felix which uses actual operator symbols for function names, instead of parser mapped names .. in most cases.. :)
For example, to make x + y work, you define: fun + : int * int -> int = "$1+$2"; rather than the old fun add: int * int -> int = "$1+$2"; Whilst this work just fine at the moment, a problem in the lexer has forced me to list all the operators as identifiers in the Dypgen lexer (i.e. hard coded). I would have prefered: symchar+ as the definition, where symchar is any one of the weirdo special characters, however for some reason this prevents /* being interpreted as the start of a C comment (even though that is given first in the lexer). For some operators you can unambiguously do this: fun < : int * int -> bool = "$1<$2"; println$ 1 < 2, < (3,4); because the second "<" isn't in an "infix" position, the parser treats it just like any name: as a prefix function application. However, there is a problem: for operators like +,-,* which have both infix and prefix interpretations, this doesn't work. In particular this fails miserably: println (+ of (int * int) (1,2)); and gets parsed like println ( ( (+ of) (int*int)) (1,2) ); probably because + is also a prefix operator. Prefix operators are NOT the same as function applications, the precedences are different. This works fine: println ( / of (int * int) (1,2) ); which demonstrates this ( / is a name like "fred" is a name, / isn't also a prefix operator). Therefore, classes introduce the old bindings such as "add" for "+", as non-virtual functions, so you can just write println (add of (int * int) (1,2)); Note, however, that when defining an instance of the class with virtual fun +, you have to make an instance with fun +, NOT fun add: the add function is just a wrapper around +. ==================================== I am not happy with the arbitrariness of definitions in classes. It is the same as in Haskell but it sucks anyhow. You are forced to define fun < to get a total order for example. Why not > ? or >= ? This is a big topic, so no more here: suffice it t say the actual requirement is to specify a conforming basis of functions, but there's no easy way to specify or check that at present. [I tried once before but caught up in knots] See next topic also: ==================================== At present when you define a type and want some functionality, you have to do this //// ctypes mode_t requires Posix_headers::sys_types_h; instance Bits[mode_t] {} // defaults to C operators instance Eq[mode_t] { fun == : mode_t * mode_t -> bool = "$1==$2"; } open Eq[mode_t]; open Bits[mode_t]; val access_mask = S_IXOTH \| S_IXGRP \| S_IXUSR; //// The "Bits" instance only works because I defaulted Bits functions to C. Since Eq's == isn't defaulted, we have to (boringly) define it. Then, we have to open the class (since it isn't open by default). A more "pleasant: interface might be like this: ctypes mode_t requires Posix_headers::sys_types_h with Eq { fun == : mode_t * mode_t -> bool = "$1==$2"; }, Bits ; This only makes sense for a class with a single type parameter. Here the "open" is automatic. This is "Kind of Object Oriented" in that the properties of a type can be specified with the type. -- john skaller skal...@users.sourceforge.net ------------------------------------------------------------------------------ Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language