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 SAA09612; Wed, 18 Jul 2001 18:44:55 +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 SAA09608 for ; Wed, 18 Jul 2001 18:44:54 +0200 (MET DST) Received: from cahors.inria.fr (cahors.inria.fr [128.93.8.84]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f6IGipb18360; Wed, 18 Jul 2001 18:44:51 +0200 (MET DST) Received: from localhost (IDENT:furuse@cahors.inria.fr [128.93.8.84]) by cahors.inria.fr (8.11.0/8.8.7) with ESMTP id f6IGip607112; Wed, 18 Jul 2001 18:44:51 +0200 To: franka@cs.uu.nl Cc: jcriddle4@home.com, caml-list@inria.fr Subject: RE: [Caml-list] Mapping onto lists In-Reply-To: References: <3B559663.14707D73@home.com> X-Mailer: Mew version 1.94.2 on Emacs 20.5 / Mule 4.1 (AOI) X-URL: http://pauillac.inria.fr/~furuse/ Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20010718184450Z.Jun.Furuse@inria.fr> Date: Wed, 18 Jul 2001 18:44:50 +0200 From: Jun Furuse X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, From: "Frank Atanassow" > > Is there any way to combine these two functions(map and my_map) so > > that the following will work? > > In short, no, but perhaps it will help to point out that: > > my_map x = map (fun f -> f x) > > Maybe it is possible in G'Caml, though. Yes. It is a simple overloading example. :-) let rec fmap v = function | [] -> [] | f::fs -> f v :: fmap v fs ;; generic rec combined_map = case | ($a -> $b) -> $a list -> $b list => List.map | $a -> ($a -> $b) list -> $b list => fmap ;; # combined_map ((+) 2) [10; 100; 100];; - : int list = [12; 102; 102] # combined_map 2 [(+) 10; (+) 100; (+) 1000];; - : int list = [12; 102; 1002] The code of the original post: >> let plus x y = x + y;; >> >> let rec map f = function >> [] -> [] >> | head::tail -> let r = f head in r :: map f tail;; >> >> map (plus 2) [10; 100; 100];; >> - : int list = [12; 102; 1002] >> >> let rec my_map f = function >> [] -> [] >> | head::tail -> let r = head f in r :: my_map f tail;; >> >> my_map 10 [plus 2; plus 4; plus 7];; >> - : int list = [12; 14; 17] >> >> combined_map 2 [plus 10; plus 100; plus 1000];; >> combined_map (plus 2) [10; 100; 100];; -- JPF ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr