caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David House <dhouse@janestreet.com>
To: Anthony Tavener <anthony.tavener@gmail.com>
Cc: "Raphaël Proust" <raphlalou@gmail.com>,
	"caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] Heterogeneous dictionary
Date: Thu, 4 Apr 2013 10:04:57 +0100	[thread overview]
Message-ID: <CAK=fH+g-FP=wmdrMoJOyn4e=ePArRMWMixRMCTwrAu5asdnLSA@mail.gmail.com> (raw)
In-Reply-To: <CAN=ouMSwQ1PP+-D4Em6a2MFUPVOS-QM4-YHj0_eSJj=yVpakqg@mail.gmail.com>

I don't quite understand the problem. Here's an example of how one
might use univ_map:

open Core.Std

module Keys : sig
  val recovery : int Univ_map.Key.t
  val resist_pain : float  Univ_map.Key.t
end = struct
  let recovery = Univ_key.Key.create "recovery" Int.sexp_of_t
  let resist_pain = Univ_key.Key.create "resist_pain" Float.sexp_of_t
end

(In practice this might be two files: keys.ml with the implementation
and keys.mli with the signature.) You can then add things as follows:

let add map ~key ~data = Univ_map.add_exn map key data in
let map =
  Univ_map.empty
  |> add ~key:Keys.recovery ~data:4
  |> add ~key:Keys.resist_pain ~data:10.
in
...

On 4 April 2013 09:37, Anthony Tavener <anthony.tavener@gmail.com> wrote:
> Thank-you for the advice and pointers, folks...
>
> Well, the common problem is still the same one I've been struggling with:
> "creating keys", and having to access them.
>
> I can't create keys "type-free" in a common module. As I figured... having
> "modifier.ml" with a bunch of Key.create will have monomorphic types which
> can't be resolved since with no usage in that module to make the type
> concrete. I had a nagging feeling I'd need a "whole-program" compiler...
>
> Instead I'd have to create keys in modules where they are used... but then I
> might have a mess of keys like Wounds.recovery, Combat.resist_pain, ... the
> problem being that only a fraction of these keys actually make sense being
> associated to a particular module, and it gets confusing to know which (of
> several candidates) I decided to stash them into. This was the attraction to
> polymorphic variants (which I rarely use) -- they give a pre-ordained unique
> ID based on a simple name... no declaration, and no module prefixing, which
> seems important to me for this case.
>
> Note that I have a "database" of tables with different types (implemented by
> first-class modules!), and it works great for the bulk of my game-state, but
> each table is well-populated and heavily used in consistent manner. These
> modifiers though... they're a bit like ad-hoc message passing, where I can
> submit any message and anywhere else add a snippet of code to interpret it
> (not that I have any of that going on, otherwise it might hold the
> solution!).
>
>
>
> On Thu, Apr 4, 2013 at 1:38 AM, Raphaël Proust <raphlalou@gmail.com> wrote:
>>
>> On Thu, Apr 4, 2013 at 1:45 AM, Anthony Tavener
>> <anthony.tavener@gmail.com> wrote:
>> > […]
>>
>> And yet-another-solution, Ocsigen's Polytable:
>> http://ocsigen.org/ocsigenserver/api/Polytables
>>
>>
>> Cheers,
>> --
>> ______________
>> Raphaël Proust
>
>

  reply	other threads:[~2013-04-04  9:05 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-04  0:45 Anthony Tavener
2013-04-04  1:29 ` Yaron Minsky
2013-04-04  2:18   ` Anthony Tavener
2013-04-04  6:19 ` Martin Jambon
2013-04-04  7:32   ` Alain Frisch
2013-04-04 18:16     ` Martin Jambon
2013-04-04  7:38 ` Raphaël Proust
2013-04-04  8:37   ` Anthony Tavener
2013-04-04  9:04     ` David House [this message]
2013-04-04 18:48       ` Anthony Tavener
2013-04-05 16:37         ` Yaron Minsky
2013-04-05 18:27           ` Anthony Tavener
2013-04-05 18:51             ` Yaron Minsky
2013-04-05 19:55               ` Anthony Tavener
2013-04-05 20:03                 ` Yaron Minsky
2013-04-05 20:27                   ` Anthony Tavener
2013-04-08  8:33                     ` David House

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='CAK=fH+g-FP=wmdrMoJOyn4e=ePArRMWMixRMCTwrAu5asdnLSA@mail.gmail.com' \
    --to=dhouse@janestreet.com \
    --cc=anthony.tavener@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=raphlalou@gmail.com \
    /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).