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 8C1397EEF6 for ; Tue, 16 Jun 2015 16:45: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: A0BUAQAMNoBVmR4844RbDoI3gR9fgx7CZAKBPkwBAQEBAQESAQEBAQEICwsHIS6EIwEBAwESEQRSBQsJAgs3AgIiEgEFARwGEwgTB4gFCJkxkGs+MYs/lm4BAQEBAQEEAQEBAQEBARuLRIUGB4JogUUFk1+LRYEzkwqCETWBFYIwHYEUPm+CRwEBAQ X-IPAS-Result: A0BUAQAMNoBVmR4844RbDoI3gR9fgx7CZAKBPkwBAQEBAQESAQEBAQEICwsHIS6EIwEBAwESEQRSBQsJAgs3AgIiEgEFARwGEwgTB4gFCJkxkGs+MYs/lm4BAQEBAQEEAQEBAQEBARuLRIUGB4JogUUFk1+LRYEzkwqCETWBFYIwHYEUPm+CRwEBAQ X-IronPort-AV: E=Sophos;i="5.13,626,1427752800"; d="scan'208";a="165613496" Received: from osiris.lip6.fr ([132.227.60.30]) by mail2-smtp-roc.national.inria.fr with ESMTP; 16 Jun 2015 16:45:45 +0200 Received: from tibre.lip6.fr (tibre.lip6.fr [132.227.74.2]) by osiris.lip6.fr (8.15.1/lip6) with ESMTP id t5GEjhhL029031 for ; Tue, 16 Jun 2015 16:45:43 +0200 (CEST) X-pt: osiris.lip6.fr Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com [209.85.212.171]) (authenticated bits=0) by tibre.lip6.fr (8.15.1/8.14.7) with ESMTPSA id t5GEjaX7000551 (version=TLSv1.2 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 16 Jun 2015 16:45:42 +0200 (MEST) Received: by wiga1 with SMTP id a1so111260567wig.0 for ; Tue, 16 Jun 2015 07:45:36 -0700 (PDT) X-Received: by 10.180.102.227 with SMTP id fr3mr43123358wib.19.1434465936151; Tue, 16 Jun 2015 07:45:36 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: =?UTF-8?Q?R=C3=A9my_El_Siba=C3=AFe_Besognet?= Date: Tue, 16 Jun 2015 14:45:25 +0000 Message-ID: To: Jacques Garrigue Cc: Mailing List OCaml Content-Type: multipart/alternative; boundary=f46d0445199b911b650518a3a024 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (osiris.lip6.fr [132.227.60.30]); Tue, 16 Jun 2015 16:45:43 +0200 (CEST) X-Scanned-By: MIMEDefang 2.75 on 132.227.60.30 Subject: Re: [Caml-list] Generic usage of Hashtbl.S with first class module --f46d0445199b911b650518a3a024 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable @Phil Eaton : I already tried this solution but it just moves the pattern matching from parameter to a let binding and does not fix the extrusion scope error. Thank anyway. Le mar. 16 juin 2015 =C3=A0 16:30, Jacques Garrigue a =C3=A9crit : > Dear R=C3=A9my, > > The trouble here is that Hashtbl.S defines an abstract type for hash > tables, and that each time you open this module, using the (module H : > Hashtbl.S) pattern, your are talking about a fresh abstract type, > incompatible with anything from the outside world. In particular, there is > no way the parameter ht could have this type, and this causes an error. > > Contrary to real functors, first-class modules do not let you connect > abstract parameterized types with the outside world. So in this case, the > only solution I see would be to pack your hash table inside the module > itself, like for an object, so that you don't need to receive ht as a > separate argument. > > Jacques Garrigue > Thank you. This was the kind of answer I expected. During this time I tried my solution without the `ht` parameter which solves my original problem. But your solution of giving the `ht` value in the module is way more general. > 2015/06/16 21:16 "R=C3=A9my El Siba=C3=AFe Besognet" : > > 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 scop= e* >> >> >> >> 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 >> >> --f46d0445199b911b650518a3a024 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
@Phil Eaton :=C2=A0
I already tried this so= lution but it just moves the pattern matching from parameter to a let bindi= ng and does not fix the extrusion scope error. Thank anyway.

=


Le=C2=A0mar. 16 j= uin 2015 =C3=A0=C2=A016:30, Jacques Garrigue <garrigue@math.nagoya-u.ac.jp> a =C3=A9crit=C2= =A0:

Dear R=C3=A9my,=

The trouble here is that Hashtbl.S defines an abstract type = for hash tables, and that each time you open this module, using the (module= H : Hashtbl.S) pattern, your are talking about a fresh abstract type, inco= mpatible with anything from the outside world. In particular, there is no w= ay the parameter ht could have this type, and this causes an error.

Contrary to real functors, first-class modules do not let yo= u connect abstract parameterized types with the outside world. So in this c= ase, the only solution I see would be to pack your hash table inside the mo= dule itself, like for an object, so that you don't need to receive ht a= s a separate argument.

Jacques Garrigue

Thank you. This was th= e kind of answer I expected.
During this time I tried my solution= without the `ht` parameter which solves my original problem. But your solu= tion of giving the `ht` value in the module is way more general.
= =C2=A0
2015/06/16 21:16 "R=C3=A9my El Siba=C3=AFe = Besognet" <remy.el-sibaie@lip6.fr>:

Hi all,<= /span>

Considering this function

let find ht x = =3D
Hashtbl.find ht x<= /div>

I would like to write a= more general `find` function which takes the module=C2=A0
as first class module in parameter= =C2=A0with 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 ident= ifier) :=C2=A0

Error: This expression has type '= ;a H.t but an expression 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 c= onstructor H.t would escape its scope


I also tried by specifying the implementation but ha= d the same problem:

let find (ty= pe 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

Any= one 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 t= han the previous function :=C2=A0

let <= span style=3D"color:rgb(121,93,163)">memo_rec (module H : Hash= tbl.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
--f46d0445199b911b650518a3a024--