Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] C++ STL and template features compared with OCaml parametric polymorphism and OO features
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Florian Hars <hars@b...>
Subject: Re: [Caml-list] C++ STL and template features compared with OCaml parametric polymorphism and OO features
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 = <fun>

# let map2 m g f x = m g (m f x);;
val map2 : ('a -> 'b -> 'b) -> 'a -> 'a -> 'b -> 'b = <fun>

# 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