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
Snd question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-08-17 (06:55)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Snd question
On Tue, 2005-08-16 at 22:42 +0100, Jon Harrop wrote:

> Has anyone done any ad-hoc polymorphism (if that's the right jargon, I mean 
> the equivalent of "+" for both int and float in SML) for containers? I 
> haven't finished it yet but I've recently been playing with a term-level 
> mini-Caml interpreter that I was going to add this functionality to. So 
> "fold", "map" and so on are built into the language and can be applied to the 
> built-in data structures set, list and array. 

Jay's Functorial ML describes how to do this properly: 
map, fold, etc, can be applied to any
polynomial type (a type built out of sums, products,
and induction). This is polyadic = functorially polymorphic,
not ad hoc.

The rules are things like: 

map <f,g> (a,b) = (map f a, map g b)

(where <f,g> is the parallel composition of f and g).

Basically, things like 'list', 'tree', etc,
are functors, and map is just a function which takes a
functor argument and returns a map for that functor.
That is, this 'map', 'fold' etc are polyadic: they accept a functor
and return another functor.

John Skaller <skaller at users dot sourceforge dot net>