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 RAA31035; Wed, 29 Sep 2004 17:32:58 +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 RAA31526 for ; Wed, 29 Sep 2004 17:32:56 +0200 (MET DST) Received: from grisu.bik-gmbh.de (grisu.bik-gmbh.de [217.110.154.194]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id i8TFWtMn027833 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 29 Sep 2004 17:32:56 +0200 Received: from [192.168.125.193] ([192.168.125.193]) by grisu.bik-gmbh.de (8.12.11/8.12.11) with ESMTP id i8TFWgmc037827; Wed, 29 Sep 2004 17:32:42 +0200 (CEST). Message-ID: <415AD595.3020009@bik-gmbh.de> Date: Wed, 29 Sep 2004 17:32:37 +0200 From: Florian Hars User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.3) Gecko/20040913 X-Accept-Language: de, de-de, en-us, en MIME-Version: 1.0 To: Jon Harrop CC: caml-list Subject: Re: [Caml-list] C++ STL and template features compared with OCaml parametric polymorphism and OO features References: <20040925225246.48566.qmail@web53010.mail.yahoo.com> <200409270259.43863.jon@jdh30.plus.com> <7f8e92aa0409270350ce0eed2@mail.gmail.com> <200409271411.30384.jon@jdh30.plus.com> In-Reply-To: <200409271411.30384.jon@jdh30.plus.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, hits=-3.2 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=2.64 X-Spam-Checker-Version: SpamAssassin 2.64 (2004-01-11) on grisu.bik-gmbh.de X-Miltered: at concorde with ID 415AD5A7.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; florian:01 hars:01 hars:01 bik-gmbh:01 caml-list:01 2004:99 mapmap:99 generic:01 val:01 val:01 florian:01 compiler:01 ocaml:01 int:01 int:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Jon Harrop wrote: > On Monday 27 September 2004 13:14, skaller wrote: >>Except you have to write: >> let List.mapmap g f x = List.map g (List.map f x) > > No, you don't have to write that. You can write a generic function which > accepts a map as an argument: > > let map_2 map f g c = map f (map g c) I made the same error at first, but this is a completely different function: # let list_map2 g f x = List.map g (List.map f x);; val list_map2 : ('a -> 'b) -> ('c -> 'a) -> 'c list -> 'b list = # let map2 m g f x = m g (m f x);; val map2 : ('a -> 'b -> 'b) -> 'a -> 'a -> 'b -> 'b = # list_map2 (fun x -> 2.0 *. x) (float_of_int) [ 1; 2; 3];; - : float list = [2.; 4.; 6.] # map2 List.map (fun x -> 2.0 *. x) (float_of_int) [ 1; 2; 3];; This expression has type int -> float but is here used with type float -> float The deforested version works (and is the only version that does in fact work for any map), but last time I looked, deforestation was considered a task for the compiler. Yours, Florian. ------------------- 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