Hi all,
Considering this function
let find ht x =
Hashtbl.find ht x
I would like to write a more general `find` function which takes the module
as first class module in parameter with the possibility to use it on
different implentations of Hashtbl.S.
let find (module H : Hashtbl.S) ht x =
H.find ht x
but it failed with this error (on the underlined identifier) :
Error: This expression has type 'a H.t but an expression was expected of type
'a H.t
The type constructor H.t would escape its scope
I also tried by specifying the implementation but had the same problem:
let find (type a) (module H : Hashtbl.S with type key = a) (ht : 'a Ht.t) (x : a) =
H.find ht x
Anyone has an idea how to achieve this thing ?
Thanks,
- Rémy El Sibaïe, LIP6
PS: at the begining, I was trying on a memoization function which has more interest than the previous function :
let memo_rec (module H : Hashtbl.S) h f =
let rec g x =
try H.find h x with
| Not_found ->
let y = f g x in
H.add h x y; y
in g