caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: caml-list@inria.fr
Subject: [Caml-list] GADTs and associative container
Date: Tue, 9 Jul 2013 22:43:12 +0200	[thread overview]
Message-ID: <20130709204312.GA30194@frosties> (raw)

Hi,

I'm wondering if one can have an ascociative container, like a Hashtbl.t
with dependent types (GADTs as the key, value depending on the key).
Something like this:

module H = struct
  type ('a, 'b) t = ('a, 'b) Hashtbl.t
  let create : type a b . int -> (a b, a) t =
		 fun x -> Hashtbl.create x
  let add : type a b . (a b, a) t -> a b -> a -> unit =
	      fun h k v -> Hashtbl.add h k v
  let find : type a b . (a b, a) t -> a b -> a =
	      fun h k -> Hashtbl.find h k
end
    
type one = ONE
type two = TWO

type _ g =
| ONEt : one g
| TWOt : two g

let () =
  let h = H.create 0
  in
  H.add h ONEt ONE;
  H.add h TWOt TWO;
  assert (H.find h ONEt = ONE);
  assert (H.find h TWOt = TWO);
  ()


BUT:

    let create : type a b . int -> (a b, a) t =
                                    ^^^
Error: Unbound type constructor b


Is there some special syntax I'm missing or is it simply impossible to
declare such a container in the abstract?

MfG
	Goswin

             reply	other threads:[~2013-07-09 20:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-09 20:43 Goswin von Brederlow [this message]
2013-07-09 20:52 ` Lukasz Stafiniak
2013-07-10  9:52   ` Leo White
2013-07-10 10:16   ` Alain Frisch
2013-07-10  2:22 ` Jeremy Yallop
2013-07-11 14:17   ` Goswin von Brederlow
2013-07-11 14:28     ` Jeremy Yallop

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=20130709204312.GA30194@frosties \
    --to=goswin-v-b@web.de \
    --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).