User-Defined Operators, Re: Function composition and currying
Johannes Waldmann
joe@informatik.uni-leipzig.de
Thu, 17 Jul 2003 09:08:54 +0200 (CEST)
On Wed, 16 Jul 2003, K. Fritz Ruehr wrote:
> I think the cutest way to get what you want here is to define a new
^^^^^^
> operator as follows:
>
> (.<) = (.) . (.)
Indeed this is cute - but let me add a general comment here:
in my code, I don't define any operators at all (only functions).
I do think that self-defined operators make a programm less readable.
All you get is a short cryptic sequence of non-alphanumeric characters.
No-one would want to export functions named f, g, f1, fg, f' etc.,
so why should this be any better with operators?
A similar discussion sometimes surfaces in mathematics -
where they have "user-defined" operators all over the place,
and especially so since LaTeX. But it's not enough if you can write down
something, you also have to talk about it - so a standard test is
to imagine you have to read out a formula (in mathematics)
or a program text (in Haskell) to someone over the phone.
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.
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?)
I could live with Haskell's predefined operators
(arithmetics, comparisons, bool-ops, (:), (++), (!), (!!), (.), ($)).
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.)
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.
--
-- Johannes Waldmann ---- http://www.informatik.uni-leipzig.de/~joe/ --
-- joe@informatik.uni-leipzig.de -- phone/fax (+49) 341 9732 204/209 --