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: Frank Atanassow <franka@c...>
Subject: RE: [Caml-list] Mapping onto lists
> 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.

---
Frank Atanassow, Information & Computing Sciences, Utrecht University
Padualaan 14, PO Box 80.089, 3508TB Utrecht, The Netherlands
Tel +31 (0)30 253-3261 Fax +31 (0)30 251-3791
---

> 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];;

-------------------
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