12345678910111213141516 |
- (* 1: Narrow down the type of the hashtable by adding a type contraint.
- * 2: Call `HashTable.mkTable` with 2 arguments:
- * 2.1: A hash function `HashString.hashString` and
- * 2.2: an equality function `op=`.
- * 3: Call the resulting function with 2 arguments:
- * 3.1: an initial size of the hash table and
- * 3.2: an exception to be thrown, when a key cannot be found in the hashtable and returning Option is not appropriate.
- *)
- val ht : (string, int) HashTable.hash_table =
- HashTable.mkTable (HashString.hashString, op=) (42, Fail "not found");
- HashTable.insert ht ("a", 1);
- HashTable.insert ht ("b", 2);
- HashTable.find ht "c"; (* -> Option *)
- HashTable.remove ht "c"; (* -> Exception *)
|