From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 252B7BC0B for ; Sun, 21 Jan 2007 13:46:00 +0100 (CET) Received: from amazone2.ujf-grenoble.fr (amazone2.ujf-grenoble.fr [152.77.2.202]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l0LCjxGN016810 for ; Sun, 21 Jan 2007 13:45:59 +0100 Received: from tana2.ujf-grenoble.fr (tana2.ujf-grenoble.fr [152.77.24.22]) by amazone2.ujf-grenoble.fr (8.13.7/8.13.7/Configured by JE 21 07 2006) with ESMTP id l0LCjxE7089466 for ; Sun, 21 Jan 2007 13:45:59 +0100 (CET) Received: from localhost (unknown [127.0.0.1]) by tana2.ujf-grenoble.fr (Postfix) with ESMTP id 8F5EA250423 for ; Sun, 21 Jan 2007 13:45:59 +0100 (CET) X-Virus-Scanned: Scanned on tana2.ujf-grenoble.fr Received: from tana2.ujf-grenoble.fr ([127.0.0.1]) by localhost (tana2.ujf-grenoble.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 87U-4-l0tw7R for ; Sun, 21 Jan 2007 13:45:59 +0100 (CET) Received: from tibre2.ujf-grenoble.fr (tibre2.ujf-grenoble.fr [152.77.24.10]) by tana2.ujf-grenoble.fr (Postfix) with ESMTP id 6197D25041C for ; Sun, 21 Jan 2007 13:45:59 +0100 (CET) Received: from ifapp1.ujf-grenoble.fr (mozart.ujf-grenoble.fr [193.54.241.5]) by tibre2.ujf-grenoble.fr (8.13.3/8.13.3) with ESMTP id l0LCjxqk044691 for ; Sun, 21 Jan 2007 13:45:59 +0100 (CET) (envelope-from san.vu-ngoc@ujf-grenoble.fr) Received: from [127.0.0.1] ([::ffff:193.54.241.13]) (TLS: TLSv1/SSLv3,256bits,AES256-SHA) by fourier.ujf-grenoble.fr with esmtp; Sun, 21 Jan 2007 13:45:58 +0100 id 0000F18B.45B36086.00003C54 Message-ID: <45B36075.5000608@ujf-grenoble.fr> Date: Sun, 21 Jan 2007 13:45:41 +0100 From: Vu Ngoc San User-Agent: IceDove 1.5.0.9 (X11/20061220) MIME-Version: 1.0 To: Caml Mailing List Subject: function definition Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 45B36087.002 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; binop:01 binop:01 match:02 match:02 defining:02 let:03 let:03 efficient:07 definition:07 mean:08 function:08 function:08 fun:08 fun:08 typically:08 I'm sure this is a basic question: what is the difference between these ways of defining a function, and what is the most efficient (I mean for the resulting function f = binop o f1 f2, which typically will be called x*1000 times) type operator = Plus | Minus;; let binop1 o f1 f2 = fun x -> match o with | Plus -> (f1 x) +. (f2 x) | Minus -> (f1 x) -. (f2 x) let binop2 o f1 f2 = match o with | Plus -> fun x -> (f1 x) +. (f2 x) | Minus -> fun x -> (f1 x) -. (f2 x) let binop3 o f1 f2 = let op = match o with | Plus -> (+.) | Minus -> (-.) in fun x -> op (f1 x) (f2 x) let binop4 o f1 f2 = fun x -> let op = match o with | Plus -> (+.) | Minus -> (-.) in op (f1 x) (f2 x) Thanks for your expertise ! San