User-Defined Operators

Christian Maeder maeder@tzi.de
Thu, 17 Jul 2003 17:21:47 +0200


Johannes Waldmann wrote:

> I do think that self-defined operators make a programm less readable.

I quite like most combinators from the pretty-printer or parsing libraries!

> And what's absolutely horrible (IMHO) is to allow the user
> to declare arbitrary precedence and associativity for his creations.
> This requires that the source text of the defining module be there,
> only to parse (i. e., build the syntax tree of) a program that uses it.

The parser does not look into imported modules. Refined expressions 
trees are setup later (before type analysis).

> And - the corresponding definitions in the standard seem rather ad-hoc: 
> we have a funny expression grammar http://haskell.org/onlinereport/exps.html,
> with arbitrary restrictions (why just ten precendence levels?)

Maybe only the numbering is nonsense, but surely you want to have 
differently strong binding infix operations in order to write i.e. 
polynoms without parens.

> I could live with Haskell's predefined operators
> (arithmetics, comparisons, bool-ops, (:), (++), (!), (!!), (.), ($)). 

Why do you outrule other useful libraries (see above). In fact ($) is 
quite cryptic (for a non-Haskeller). An what should the difference be 
between (!!) and (!)? (I know it's the type.) In fact. I would like to 
reuse (sometimes) a predefined operator for another purposes (not easily 
  covered by type class overloading and without hiding or qualifying 
prelude operators).

Example: multiply a scalar with a vector. Without operators, formulae 
may become really horribly long.

> I often use them, and I sometimes overload them (arithmetics, comparisons), 
> but nothing more. (This is the design of Ada - there are operators,
> you can overload them, but you cannot change their precedence,
> or add new ones - so you can always parse a program text.)

Ada has true ad-hoc overloading, though.

> Anyway, this was just for the record (I'm a happy Haskell user,
> I just ignore some of its features :-), so back to real work now.

I fully agree with these too lines.

Christian