RE: Functional composition operator?

From: Don Syme (dsyme@microsoft.com)
Date: Tue Dec 08 1998 - 21:09:49 MET

From: Don Syme <dsyme@microsoft.com>
To: "'Pierre Weis'" <Pierre.Weis@inria.fr>, whitley@cse.buffalo.edu
Subject: RE: Functional composition operator?
Date: Tue, 8 Dec 1998 12:09:49 -0800

>
> -- it only save a few characters in programs
> (Compare
> let h = f o g
> with
> let h x = f (g x);;)

As you say, you can always define the infix identifier, so there's no
hassle, i.e. I'm not complaining. However, the comparison should be
f1 << f2 << f3 << f4
v.
(fun x -> f1(f2(f3(f4 x))))

because we may not be binding the on-the-fly value to a name. Saving
parentheses is clearly a good idea - most the ML syntax is directed to this.
Even worse consider

f1 << f2 x y z << f3 << f4 a b

v.
(let f4' = f4 a b in
let f2' = f2 x y z in
(fun x -> f1(f2' z(f3(f4' x)))))

since in the latter case we may be taking advantage of the partial
evaluation of the closures to, for example, precompute some tables based on
the information in x,y,z and a,b. I know which I prefer!

In 16,000 lines implementing the interactive theorem prover DECLARE there
are 220 uses of composition, so one every 70 lines or so. There are 500
uses of "map", so it's relatively common in that one random example at
least.

Cheers,
Don

------------------------------------------------------------------------
At the lab: At home:
Microsoft Research Cambridge 11 John St
St George House CB1 1DT
Cambridge, CB2 3NH, UK
Ph: +44 (0) 1223 744797 Ph: +44 (0) 1223 722244
http://research.microsoft.com/users/dsyme
email: dsyme@microsoft.com
"You've been chosen as an extra in the movie