From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA01077 for caml-redistribution; Tue, 8 Dec 1998 19:28:07 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA25876 for ; Tue, 8 Dec 1998 18:02:30 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id SAA01178; Tue, 8 Dec 1998 18:02:21 +0100 (MET) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA29130; Tue, 8 Dec 1998 18:02:21 +0100 (MET) From: Pierre Weis Message-Id: <199812081702.SAA29130@pauillac.inria.fr> Subject: Re: Functional composition operator? To: whitley@cse.buffalo.edu (John Whitley) Date: Tue, 8 Dec 1998 18:02:21 +0100 (MET) Cc: caml-list@inria.fr In-Reply-To: <13932.45585.522844.651609@hadar.cs.Buffalo.EDU> from "John Whitley" at Dec 8, 98 00:23:59 am X-Mailer: ELM [version 2.4 PL24 ME8] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: weis > Andrew Kay wrote, in the caml-list archives: > > We are in the process of converting our Caml code into OCaml, and > > have a problem choosing an infix syntax for function composition > > [...] What do other OCaml people use for function composition? Is > > there standard emerging? > > I found no answer in the archives, so I'd like to raise the same > question again: is there a consensus for choice of infix composition > operator? Failing that, is there some design principle that warranted > its omission? > > Thanks, > John Whitley The normal infix operator should be a o, or more precisely a $\circ$ symbol. Unfortunately if we add o in the syntax of Caml, this will be a bit strange to have this identifier as an infix operation (moreover this implies difficult to explain syntax errors in programs). In fact we discourage the usage of functional composition as a general programming tool, since: -- it only save a few characters in programs (Compare let h = f o g with let h x = f (g x);;) -- it breaks the polymorphism (if defined as let h = f o g h is not generalized, since its definition is a function application, whereas inline expansion of functional composition let h x = f (g x) being the definition of a function is properly generalized.) -- it is not so clear, especially in case of composition of curried functions (Consider let f x y z = x + y + z then the compositions f o (f 2 3) or (f 1) o (f 2 3)) It is still possible to define a composition operator to use in trivial cases. So you may choose any multi-character infix operator such as ++, if you really need functional composition. Best regards, Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/