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 (a,b) = (map f a, map g b) (where 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