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 78B217EEB4 for ; Wed, 6 Feb 2013 09:19:44 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of christophe.papazian@gmail.com) identity=pra; client-ip=74.125.82.50; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="christophe.papazian@gmail.com"; x-sender="christophe.papazian@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of christophe.papazian@gmail.com designates 74.125.82.50 as permitted sender) identity=mailfrom; client-ip=74.125.82.50; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="christophe.papazian@gmail.com"; x-sender="christophe.papazian@gmail.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@mail-wg0-f50.google.com) identity=helo; client-ip=74.125.82.50; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="christophe.papazian@gmail.com"; x-sender="postmaster@mail-wg0-f50.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjcCAO4RElFKfVIyjWdsb2JhbABFhgG6PhYOAQEBAQkJCwkSBiOCTRMGARseAxIQXhEBBQEiiBEBAw+aC4JwjDSCe4RfChknDVmIdwEFDJBuYQOWIYVwiQA/hCI X-IPAS-Result: AjcCAO4RElFKfVIyjWdsb2JhbABFhgG6PhYOAQEBAQkJCwkSBiOCTRMGARseAxIQXhEBBQEiiBEBAw+aC4JwjDSCe4RfChknDVmIdwEFDJBuYQOWIYVwiQA/hCI X-IronPort-AV: E=Sophos;i="4.84,614,1355094000"; d="scan'208";a="1576267" Received: from mail-wg0-f50.google.com ([74.125.82.50]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 06 Feb 2013 09:19:17 +0100 Received: by mail-wg0-f50.google.com with SMTP id es5so855253wgb.17 for ; Wed, 06 Feb 2013 00:19:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:content-type:content-transfer-encoding:subject:date :message-id:to:mime-version:x-mailer; bh=0gbilTRiA2mf4iO1TZsoptt1H8c76CTdYWHH+flD6J8=; b=tTtkUK2Lb+v/sHgwASP2c1pwmfE2il97THYOIzM3MLTyBnsOEyGoO4dUUa2sgbTG39 z6O2dGE/J73CP/V2hRwsYwRoG5+DJoU6zbMTMIOzJfOUh8zaGEq2JtDM01kh57WimtQh qmSvWqq44FHv5022pu+REL7F+aFZEXkLQkNigoEGPATcAKNlgl1bFf3iZt+RJ8mXSLpK PWa7eSBE5tTQwBiYMH56a/SZ+hG4Lm9tp+gPBjALnoEd4Hg5YUeYdKgLUFUIrq1CNODI ffZTFuS9X43QbrTh/ynuTdlHyVaJrJYtBX/m0lrPzpFjUfr7nZUi8HNW+1QcowKOTM0x o/FA== X-Received: by 10.194.48.74 with SMTP id j10mr47723470wjn.36.1360138756911; Wed, 06 Feb 2013 00:19:16 -0800 (PST) Received: from [157.169.110.215] ([157.169.110.215]) by mx.google.com with ESMTPS id ex1sm1590305wib.7.2013.02.06.00.19.15 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 06 Feb 2013 00:19:16 -0800 (PST) From: Christophe Papazian Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Date: Wed, 6 Feb 2013 09:19:16 +0100 Message-Id: To: Caml List Mime-Version: 1.0 (Apple Message framework v1283) X-Mailer: Apple Mail (2.1283) Subject: [Caml-list] Memoize GADT Hi, this must be a very basic question for some of you, sorry for the inconveni= ence : When I have function "f" of type (a -> b), I can easily add a layer to that= function to memoize the result by using a (a,b) Hashtbl.t to store the res= ults of the expensive to compute "f". let mf =3D let e =3D Hashtbl.create 0 in ( fun x -> try Hashtbl.find e x wi= th Not_found -> let res =3D f x in Hashtbl.add e x res; res ) But now, I have a function "g"=20 let g (type a) : a gadt -> a =3D .... And If I apply the same method, type a becomes weak (_'a). Is there something simple to memoize that function as easy as the previous = example and keep its polymorphism ? I think not, but I hope to be wrong. Thanks Christophe