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: skaller <skaller@u...>
Subject: Re: [Caml-list] C++ STL and template features compared with OCaml parametric polymorphism and OO features
On Mon, 2004-09-27 at 11:59, Jon Harrop wrote:

>  In practice, I'm all for 
> aggressive factoring but I can't see what we're factoring here...

Sure you can. Consider:

type 'a F = A | B of 'a | C of 'a * 'a * int 

Can you write a map function for this? Of course you
can! What about:

type 'a F = A of int | C of 'a * int | X of 'a F * 'a

Yes, of course you can!

Its obvious how to do it! 

There *exists* a universal algorithm in your head
for writing map functions. But this pattern cannot
be encoded in Ocaml as an HOF:

map: 'a 'F -> ('a -> 'b) -> 'b 'F

You can do this provided you have only types built
from variants, tuples, and recursion (no function types).

In fact you could probably write this function
in camlp4 from the definition of each type
for which you need a map. 

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net



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