From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id BAA32347; Tue, 24 Aug 2004 01:16:18 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 BAA31806 for ; Tue, 24 Aug 2004 01:16:16 +0200 (MET DST) Received: from us19.unix.fas.harvard.edu (us19.unix.fas.harvard.edu [140.247.35.199]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i7NNGFRM010666 for ; Tue, 24 Aug 2004 01:16:15 +0200 Received: from ls02.fas.harvard.edu (ls02.fas.harvard.edu [140.247.34.102]) by us19.unix.fas.harvard.edu (8.12.11/8.12.11) with ESMTP id i7NNGEGc009881 for ; Mon, 23 Aug 2004 19:16:14 -0400 Received: by ls02.fas.harvard.edu (Postfix, from userid 19885) id D31911C003; Mon, 23 Aug 2004 19:16:09 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by ls02.fas.harvard.edu (Postfix) with ESMTP id CCB5B24024 for ; Mon, 23 Aug 2004 19:16:09 -0400 (EDT) Date: Mon, 23 Aug 2004 19:16:09 -0400 (EDT) From: Michael Alexander Hamburg To: caml-list@pauillac.inria.fr Subject: Re: [Caml-list] Q: Correct locations for macro camlp4 extensions In-Reply-To: <20040823182936.GA8152@annexia.org> Message-ID: References: <1093281685.412a2795efb43@webmail.fas.harvard.edu> <20040823182936.GA8152@annexia.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at concorde with ID 412A7ABF.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 camlp:01 2004:99 0400,:01 haskell:01 val:01 haskell:01 foo:01 camlp:01 currying:01 crm:99 consultancy:99 lest:01 runtime:01 ltd:98 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, 23 Aug 2004, Richard Jones wrote: > On Mon, Aug 23, 2004 at 01:21:25PM -0400, Michael Alexander Hamburg wrote: > > [...] Or does it enable > > expressions like (/ 5) or (+ 3) as in Haskell (that would be cool...)? > > You mean like: > > # let f = ((/) 5);; > val f : int -> int = > # f 1;; > - : int = 5 > > and similarly ((+) 3)? Or do these expressions do something more > profound that I can't now recall? -- It's been a good 10 years since I > did any serious Haskell. Actually, this sort of proves my point. (/ 5) divides its argument by 5 in Haskell, which is what I at least would expect such an expression to do. On the other hand, ((/) 5) divides 5 by its argument, because the first argument to an operator goes on the left, not the right. To write the equivalent of (/ 5), you have to write (fun x -> x/5). More important than tripling the number of characters is that non-commutative operators make the ((op) foo) notation confusing. If I ever come to understand camlp4, and a module to enable this syntax isn't there, I'll try to add it, because I find it handy in Haskell. Another syntax construction that I might write up (which I'm not aware of in any programming language) would be something like (f _ x _ _ y) translates into (fun p1 p2 p3 -> f p1 x p2 p3 y) I don't think that the use of _ can be ambiguous in an expression like this... any counterexamples? >>From my knowledge of Camlp4, this seems like it would be a lot more difficult than the Haskell operator currying. > Rich. > > -- > Richard Jones. http://www.annexia.org/ http://www.j-london.com/ > Merjis Ltd. http://www.merjis.com/ - improving website return on investment > http://www.winwinsales.co.uk/ - CRM improvement consultancy Regards, Mike P.S. Lest you think I've gone compactness-crazy, I've been doing a fair amount of symbolic and functional manipulation in O'Caml, and compressed notation for functions helps me a lot. When I have n lists of pairs to sort by the first element of the tuple, or some other function like that, it saves me a significant amount of programming effort to write # let (<-<<) f g a b = f (g a) (g b);; or # let sort_by g a b = sort (compare (g a) (g b));; so that I can write # sort (compare <-<< fst) l;; or # sort_by fst l instead of # sort (fun a b -> compare (fst a) (fst b)) l;; I know that the last form is probaly faster at runtime than the first ones, but my programs don't have to run fast. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners