Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Mapping onto lists
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jay Riddle <jcriddle4@h...>
Subject: [Caml-list] Mapping onto lists


Is there any way to combine these two functions(map and my_map) so
that the following will work?

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 mapping function *)
combined_map 2        [plus 10; plus 100; plus 1000];;
combined_map (plus 2) [10; 100; 100];;

--JayR x8-1335
-------------------
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