Comparison of programming languages (associative array): Difference between revisions

Content deleted Content added
Objective-C (Cocoa/GNUstep): copy editing and (crudely) referencing
OCaml: copy editing and linking
Line 1,128:
</syntaxhighlight>
 
=== [[OCaml]] ===
The [[OCaml]] programming language provides three different associative containers. The simplest is a list of pairs:
 
<syntaxhighlight lang=OCaml>
Line 1,158:
</syntaxhighlight>
 
The code above uses OCaml's default hash function <code>Hashtbl.hash</code>, which is defined automatically for all types. If you wanted toTo use youra ownmodified hash function, you can use the functor interface <code>Hashtbl.Make</code> to create a module, likesuch as with <code>Map</code> below.
 
Finally, functional maps (represented as immutable balanced binary trees):
Line 1,173:
</syntaxhighlight>
 
Note that in order to use <code>Map</code>, you have to provide the functor <code>Map.Make</code> with a module which defines the key type and the comparison function. The third-party library ExtLib provides a polymorphic version of functional maps, called [<code>PMap</code><ref>https://web.archive.org/web/20081211233540/http://ocaml-extlib.googlecode.com/svn/doc/apiref/PMap.html PMap]</ref>, wherewhich youis provideprovided the comparison function when creating theupon mapcreation.
 
Lists of pairs and functional maps both provide a purely functional interface. InBy contrast, hash tables provide an imperative interface. For many operations, hash tables are significantly faster than lists of pairs and functional maps.
 
=== [[OptimJ]] ===