caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christophe Papazian <christophe.papazian@gmail.com>
To: Caml List <caml-list@inria.fr>
Subject: [Caml-list] Memoize GADT
Date: Wed, 6 Feb 2013 09:19:16 +0100	[thread overview]
Message-ID: <A0D04133-A54F-458E-A584-8139F90C2711@gmail.com> (raw)

Hi,

this must be a very basic question for some of you, sorry for the inconvenience :

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 results of the expensive to compute "f".

let mf = let e = Hashtbl.create 0 in ( fun x -> try Hashtbl.find e x with Not_found -> let res = f x in Hashtbl.add e x res; res )

But now, I have a function "g" 
	let g (type a) : a gadt -> a = ....

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


             reply	other threads:[~2013-02-06  8:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-06  8:19 Christophe Papazian [this message]
2013-02-06  9:50 ` Alain Frisch
2013-02-06  9:55 ` Gabriel Scherer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=A0D04133-A54F-458E-A584-8139F90C2711@gmail.com \
    --to=christophe.papazian@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).