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 48A557EEF6 for ; Tue, 16 Jun 2015 15:03:55 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of me@eatonphil.com) identity=pra; client-ip=67.222.38.55; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="me@eatonphil.com"; x-sender="me@eatonphil.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of me@eatonphil.com designates 67.222.38.55 as permitted sender) identity=mailfrom; client-ip=67.222.38.55; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="me@eatonphil.com"; x-sender="me@eatonphil.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@gproxy5-pub.mail.unifiedlayer.com) identity=helo; client-ip=67.222.38.55; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="me@eatonphil.com"; x-sender="postmaster@gproxy5-pub.mail.unifiedlayer.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CzAQBeHoBVnDcm3kNbgkWBH18GgxisO5AwhXgCgThTAQEBAQEBEgEBAQEBBg0JCSEuhCMBAQMBEhEEUgULCQILNwICIhMFHQYTIogFCAUImGyQaz4xiz+WegEBAQEBAQEBAQEBAQEBAQEBAQEBGItEhQIEB4JogUUFk1+EUoZzgXSGLxaOJ4E4hDtTgkcBAQE X-IPAS-Result: A0CzAQBeHoBVnDcm3kNbgkWBH18GgxisO5AwhXgCgThTAQEBAQEBEgEBAQEBBg0JCSEuhCMBAQMBEhEEUgULCQILNwICIhMFHQYTIogFCAUImGyQaz4xiz+WegEBAQEBAQEBAQEBAQEBAQEBAQEBGItEhQIEB4JogUUFk1+EUoZzgXSGLxaOJ4E4hDtTgkcBAQE X-IronPort-AV: E=Sophos;i="5.13,626,1427752800"; d="scan'208";a="165588093" Received: from gproxy5-pub.mail.unifiedlayer.com ([67.222.38.55]) by mail2-smtp-roc.national.inria.fr with SMTP; 16 Jun 2015 15:03:43 +0200 Received: (qmail 18205 invoked by uid 0); 16 Jun 2015 13:03:42 -0000 Received: from unknown (HELO cmgw3) (10.0.90.84) by gproxy5.mail.unifiedlayer.com with SMTP; 16 Jun 2015 13:03:42 -0000 Received: from box1101.bluehost.com ([50.87.248.101]) by cmgw3 with id h6wk1q00d2C0F16016wnR2; Tue, 16 Jun 2015 12:56:49 -0600 X-Authority-Analysis: v=2.1 cv=Bb1LjNd2 c=1 sm=1 tr=0 a=o2B3Xfj7TB0ghplPD/Fs9Q==:117 a=o2B3Xfj7TB0ghplPD/Fs9Q==:17 a=cNaOj0WVAAAA:8 a=f5113yIGAAAA:8 a=lKpqOWG9AAAA:8 a=pGLkceISAAAA:8 a=1XWaLZrsAAAA:8 a=WuLPXI9HoVIA:10 a=xhaaRbXrb-wA:10 a=XAFQembCKUMA:10 a=snBypVClAAAA:8 a=SIvUiwFSFRugnM9FKxwA:9 a=QEXdDO2ut3YA:10 a=Wp4VLjbfO4QA:10 a=DNDnabsPR7iVRSCWugsA:9 a=XC3USqwYMrwPsZs8:21 Received: from [209.85.214.176] (port=36450 helo=mail-ob0-f176.google.com) by box1101.bluehost.com with esmtpsa (TLSv1.2:AES128-GCM-SHA256:128) (Exim 4.84) (envelope-from ) id 1Z4qWe-0001AM-Lb for caml-list@inria.fr; Tue, 16 Jun 2015 07:03:36 -0600 Received: by obctg8 with SMTP id tg8so10723842obc.3 for ; Tue, 16 Jun 2015 06:03:34 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.202.45.23 with SMTP id t23mr201943oit.110.1434459814017; Tue, 16 Jun 2015 06:03:34 -0700 (PDT) Received: by 10.202.14.143 with HTTP; Tue, 16 Jun 2015 06:03:33 -0700 (PDT) In-Reply-To: References: Date: Tue, 16 Jun 2015 09:03:33 -0400 Message-ID: From: Phil Eaton To: =?UTF-8?Q?R=C3=A9my_El_Siba=C3=AFe_Besognet?= Cc: "caml-list@inria.fr" Content-Type: multipart/alternative; boundary=001a1137a7f6a8d7a50518a2336e X-Identified-User: {1258:box1101.bluehost.com:eatonphi:eatonphil.com} {sentby:smtp auth 209.85.214.176 authed with me@eatonphil.com} Subject: Re: [Caml-list] Generic usage of Hashtbl.S with first class module --001a1137a7f6a8d7a50518a2336e Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Until you get a better response, I can point you in a direction. You want to look up first-class modules . It looks like you will want something like this (taken from that page): let to_int m =3D let module M =3D (val m : X_int) in M.x Except yours will look more like: let find h ht x =3D let module H =3D (val h : Hashtbl.S) in H.find *ht* x Sorry about the awful formatting. On Tue, Jun 16, 2015 at 8:15 AM, R=C3=A9my El Siba=C3=AFe Besognet < remy.el-sibaie@lip6.fr> wrote: > 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 > > --=20 Phil Eaton http://eatonphil.com --001a1137a7f6a8d7a50518a2336e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Until you get a better response, I can point you in a dire= ction. You want to look up first-class modules. It looks like you will = want something like this (taken from that page):

let to_int m =3D
    let module M =3D (val m : X_int) in
    M.x

Except yours=
 will look more like:

let find h ht x =3D
let module H =3D (= val h : Hashtbl.S) in
H.find ht x

Sor=
ry about the awful formatting.
On Tue, Jun 16, 2015 at 8:15 AM, R=C3=A9my El = Siba=C3=AFe Besognet <remy.el-sibaie@lip6.fr> wrote:
Hi all,

=
= 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



--
--001a1137a7f6a8d7a50518a2336e--