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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 6DA097EEF6 for ; Tue, 16 Jun 2015 16:30:11 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of jacques.garrigue@gmail.com) identity=pra; client-ip=209.85.212.169; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="jacques.garrigue@gmail.com"; x-sender="jacques.garrigue@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of jacques.garrigue@gmail.com designates 209.85.212.169 as permitted sender) identity=mailfrom; client-ip=209.85.212.169; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="jacques.garrigue@gmail.com"; x-sender="jacques.garrigue@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wi0-f169.google.com) identity=helo; client-ip=209.85.212.169; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="jacques.garrigue@gmail.com"; x-sender="postmaster@mail-wi0-f169.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0B3BQBYMoBVlKnUVdFbgkWBfgaDGKwXmAYHTAEBAQEBARIBAQEBBwsLCR8whCMBAQMBEhEEGQE4AQMBCwEFAwILNwICIhIBBQEcBhMbB4d4AwoImTGQaz4xiz+EZIwbJw1IhHEBAQEHAQEBAQEXAQUOizaHdYFFBYxphnaLRYEzkwqCERIjgRVggVAdgWEvMYJHAQEB X-IPAS-Result: A0B3BQBYMoBVlKnUVdFbgkWBfgaDGKwXmAYHTAEBAQEBARIBAQEBBwsLCR8whCMBAQMBEhEEGQE4AQMBCwEFAwILNwICIhIBBQEcBhMbB4d4AwoImTGQaz4xiz+EZIwbJw1IhHEBAQEHAQEBAQEXAQUOizaHdYFFBYxphnaLRYEzkwqCERIjgRVggVAdgWEvMYJHAQEB X-IronPort-AV: E=Sophos;i="5.13,626,1427752800"; d="scan'208";a="136499972" Received: from mail-wi0-f169.google.com ([209.85.212.169]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 16 Jun 2015 16:30:10 +0200 Received: by wibdq8 with SMTP id dq8so21520667wib.1 for ; Tue, 16 Jun 2015 07:30:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=6M9muS6+6iYtHTPaQGK1NqpGbZc/rs5xkf9ja3XAgXI=; b=yVP2MEECZ2Qh+8PcTZ1d34OW1rnNQTczXfXV50FDEPwgOkE+0edfDu0ZNi5etfAoqL uP5AincWd9k8s4NID/HAyuUIPYZhEEdF5hy/TOvCsBbpaFtsqPrmx1vNdhjeXysD2/7M 8fa00PDMHqiwsbmbAWNID71h/br0XdPfEUTEciCqdnJE6kta4gjfhJmaSwtsyP2C0kZZ tUHWTUzwgDryNCLei3cNYWvVE8euPCvwF1ovrxsYPRyyROw24x5auRLLskZLxJJEc42G rsJWnny+4GXgmcRj2wuiXKoiS6dateKZ5SkSvwOP6rxCar7MW9uURH40dRnljpZGCzWx MsXA== MIME-Version: 1.0 X-Received: by 10.180.72.176 with SMTP id e16mr7626153wiv.12.1434465010265; Tue, 16 Jun 2015 07:30:10 -0700 (PDT) Sender: jacques.garrigue@gmail.com Received: by 10.194.139.36 with HTTP; Tue, 16 Jun 2015 07:30:09 -0700 (PDT) Received: by 10.194.139.36 with HTTP; Tue, 16 Jun 2015 07:30:09 -0700 (PDT) In-Reply-To: References: Date: Tue, 16 Jun 2015 23:30:09 +0900 X-Google-Sender-Auth: LF59Nbcks8iWGI5uiYwHmZXHm-E Message-ID: From: Jacques Garrigue To: =?UTF-8?Q?R=C3=A9my_El_Siba=C3=AFe_Besognet?= Cc: Mailing List OCaml Content-Type: multipart/alternative; boundary=f46d043c07926131ea0518a369e0 Subject: Re: [Caml-list] Generic usage of Hashtbl.S with first class module --f46d043c07926131ea0518a369e0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 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 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 > > --f46d043c07926131ea0518a369e0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

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

2015/06/16 21:16 "R=C3=A9my El Siba=C3=AFe = Besognet" <remy.el-sibaie= @lip6.fr>:
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
--f46d043c07926131ea0518a369e0--