Putting the fun in functional programming since 2005!
Friday, 4 May 2012
Map and fold functions that are generic over the kind of collection
There are two main solutions in OCaml:
Jacques Garrigue already implemented a syntactically-light but inefficient approach for many data structures several years ago. You just wrap the collections in objects that provide a map method. Then you can do collection#map to use the map function for any kind of collection. This is general because it allows different kinds of data structures to be substituted at run time. However, this is not very useful in practice so the approach was never widely adopted.