English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2004-09-29 (16:53)
From: Jon Harrop <jon@j...>
Subject: Re: [Caml-list] Factoring HOFs [was Re: C++ STL...]
On Wednesday 29 September 2004 16:32, Florian Hars wrote:
> I made the same error at first, but this is a completely different
> function:

Yipes! Ok, so I'm missing some typing subtlety. Why does this end up with a 
single polymorphic type:

# let map_2 m g f x = m g (m f x);;
val map_2 : ('a -> 'b -> 'b) -> 'a -> 'a -> 'b -> 'b = <fun>
# let mapmap2 g f x = map_2 List.map g f x;;
val mapmap2 : ('a -> 'a) -> ('a -> 'a) -> 'a list -> 'a list = <fun>

Rather than being equivalent to:

# let mapmap g f x = List.map g (List.map f x);;
val mapmap : ('a -> 'b) -> ('c -> 'a) -> 'c list -> 'b list = <fun>

It looks like the "m" argument to map_2 is assumed to have the same type when 
applied to "f x" as when applied to "g (f x)". Sounds like this might be 
related to polymorphic recursion...


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