caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] GADTs and associative container
@ 2013-07-09 20:43 Goswin von Brederlow
  2013-07-09 20:52 ` Lukasz Stafiniak
  2013-07-10  2:22 ` Jeremy Yallop
  0 siblings, 2 replies; 7+ messages in thread
From: Goswin von Brederlow @ 2013-07-09 20:43 UTC (permalink / raw)
  To: caml-list

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-07-11 14:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-09 20:43 [Caml-list] GADTs and associative container Goswin von Brederlow
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

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).