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 KAA08412 for caml-redistribution; Wed, 9 Dec 1998 10:11:55 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA07381 for ; Tue, 8 Dec 1998 21:32:36 +0100 (MET) Received: from deneb.fac.cs.cmu.edu (DENEB.FAC.CS.CMU.EDU [128.2.198.60]) by nez-perce.inria.fr (8.8.7/8.8.7) with SMTP id VAA12702 for ; Tue, 8 Dec 1998 21:32:29 +0100 (MET) Received: from DENEB.FAC.CS.CMU.EDU by deneb.fac.cs.cmu.edu id aa13054; 8 Dec 98 15:32 EST Date: Tue, 8 Dec 1998 15:32:17 -0500 (EST) From: John Prevost Sender: weis To: caml-list@inria.fr Subject: RE: Functional composition operator? In-Reply-To: <199812081808.SAA01875@byrd.sharp.co.uk> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Tue, 8 Dec 1998, Andrew Kay wrote: > In the end we settled on >> and << for forward and reverse > composition respectively, satisfying the equations: {...} > We're still interested to know if other people have different approaches. This seems to be a very reasonable approach! I'd been thinking recently about this very question, and also about reverse composition, and the chevrons handle this distinction quite nicely. As for the person who said that composition isn't necessary: there are places where it is useful, in any case. Take the following example of an extensible printf system using continuation-passing in O'Caml (translated from an SML version shown to me by Franklin Chen): let id x = x (* continuation, string, args *) let f_int k s x = k (s ^ string_of_int x) let f_str k s x = k (s ^ x) let f_lit x k s = k (s ^ x) let f_eol k s = k (s ^ "\n") let f_list t k s = function | [] -> k (s ^ "[]") | xs -> let rec loop l k s = match l with | [x] -> t (fun s -> k (s ^ "]")) s x | (x::xs) -> t (fn s => loop xs k (s ^ ", ")) s x in loop xs k (s ^ "[") let printf c = c id "" (* "3 is foo[2, 3, 4]\n" *) let foo = printf (f_int $ f_lit " is " $ f_str $ (f_lis f_int) $ f_eol) 3 "foo" [2, 3, 4];; where $ is normal functional composition. Notice that this definition of formatting has similar (although not exactly the same, because it only support writing out a string (this could be fixed, and possibly in a generic way)) nice properties to O'Caml's Printf.printf stuff and formats, but doesn't require the compiler to know about a special type of formats. Note also that composition serves a very good purpose in this case--you couldn't do this easily without it, or with a prefix composition operator. jmp.