From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 2EBC97EEF6 for ; Tue, 16 Jun 2015 14:15:45 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of remy.el-sibaie@lip6.fr) identity=pra; client-ip=132.227.60.30; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="remy.el-sibaie@lip6.fr"; x-sender="remy.el-sibaie@lip6.fr"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of remy.el-sibaie@lip6.fr designates 132.227.60.30 as permitted sender) identity=mailfrom; client-ip=132.227.60.30; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="remy.el-sibaie@lip6.fr"; x-sender="remy.el-sibaie@lip6.fr"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of postmaster@osiris.lip6.fr designates 132.227.60.30 as permitted sender) identity=helo; client-ip=132.227.60.30; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="remy.el-sibaie@lip6.fr"; x-sender="postmaster@osiris.lip6.fr"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0B5AQDLEoBVmR4844RbgkWFHKw4AUyXHkwBAQEBAQESAQEBAQEICwsHIS6EOxEEaw03AiQSAQUBIjWIDZhUjTqDMT4xiz+XI5M5gUUFk1+LRZZONYEVgXuCJIM2AQEB X-IPAS-Result: A0B5AQDLEoBVmR4844RbgkWFHKw4AUyXHkwBAQEBAQESAQEBAQEICwsHIS6EOxEEaw03AiQSAQUBIjWIDZhUjTqDMT4xiz+XI5M5gUUFk1+LRZZONYEVgXuCJIM2AQEB X-IronPort-AV: E=Sophos;i="5.13,626,1427752800"; d="scan'208";a="165575606" Received: from osiris.lip6.fr ([132.227.60.30]) by mail2-smtp-roc.national.inria.fr with ESMTP; 16 Jun 2015 14:15:44 +0200 Received: from tibre.lip6.fr (tibre.lip6.fr [132.227.74.2]) by osiris.lip6.fr (8.15.1/lip6) with ESMTP id t5GCFiQw020672 for ; Tue, 16 Jun 2015 14:15:44 +0200 (CEST) X-pt: osiris.lip6.fr Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com [209.85.212.182]) (authenticated bits=0) by tibre.lip6.fr (8.15.1/8.14.7) with ESMTPSA id t5GCFcsd009633 (version=TLSv1.2 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 16 Jun 2015 14:15:39 +0200 (MEST) Received: by wiga1 with SMTP id a1so107006334wig.0 for ; Tue, 16 Jun 2015 05:15:38 -0700 (PDT) X-Received: by 10.180.94.168 with SMTP id dd8mr41851790wib.76.1434456938697; Tue, 16 Jun 2015 05:15:38 -0700 (PDT) MIME-Version: 1.0 From: =?UTF-8?Q?R=C3=A9my_El_Siba=C3=AFe_Besognet?= Date: Tue, 16 Jun 2015 12:15:28 +0000 Message-ID: To: "caml-list@inria.fr" Content-Type: multipart/alternative; boundary=f46d0444816746e2360518a1888a X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (osiris.lip6.fr [132.227.60.30]); Tue, 16 Jun 2015 14:15:44 +0200 (CEST) X-Scanned-By: MIMEDefang 2.75 on 132.227.60.30 Subject: [Caml-list] Generic usage of Hashtbl.S with first class module --f46d0444816746e2360518a1888a Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi all, Considering this function let find ht x =3D 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 =3D 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 =3D a) (ht : 'a Ht.t) (x : a) =3D H.find ht x Anyone has an idea how to achieve this thing ? Thanks, - R=C3=A9my El Siba=C3=AFe, 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 =3D let rec g x =3D try H.find h x with | Not_found -> let y =3D f g x in H.add h x y; y in g --f46d0444816746e2360518a1888a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi all,

Considering this function

let find ht x =3D
Hashtbl.find ht x

I = would like to write a more general `find` function which takes the module= =C2=A0
as first cla= ss module in parameter=C2=A0with the possibility to use it on
different implentations of Hashtbl.S.

let find (module H =
: Hashtbl.S) ht<=
/span> x =3D
H.find ht x

but it failed with this error (on the underlined identifier) :=C2=A0<= /span>

Error: This expression has type 'a H.t but an e= xpression was expected of type
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= 'a H.t
=C2=A0 =C2=A0 =C2=A0 =C2=A0The type constructor H.t wo= uld escape its scope


=
I also tried by specifying the implementation but had the same proble= m:

let find (type a) (module= H : Hashtbl.S = with type key =3D a) (ht : '= ;a Ht.t) (x : a) =3D=C2=A0
H.find ht x=C2=A0

<= /div>
Anyone has an idea how to achieve this thing ?

Thanks,<= /div>
- R=C3=A9my El Siba=C3=AFe, LIP6



=
= PS: at the begining, I was trying on a memoization function which has more = interest than the previous function :=C2=A0

let memo_rec<= /span> (module H= : Hashtbl.S) <= span class=3D"pl-v" style=3D"color:rgb(29,62,129)">h f =3D
let rec g x<= /span> =3D
try H.find h x with
| Not_found ->
let y =3D f g x in
H.add h x y; y
in g
--f46d0444816746e2360518a1888a--