caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Lukasz Stafiniak <lukstafi@gmail.com>
To: Goswin von Brederlow <goswin-v-b@web.de>
Cc: Caml <caml-list@inria.fr>
Subject: Re: [Caml-list] GADTs and associative container
Date: Tue, 9 Jul 2013 22:52:20 +0200	[thread overview]
Message-ID: <CAJMfKEVVZem2rrSZ0GUz7LvwN8_nGWW9+zMzcB-zwesPrXqEjQ@mail.gmail.com> (raw)
In-Reply-To: <20130709204312.GA30194@frosties>

[-- Attachment #1: Type: text/plain, Size: 1115 bytes --]

On Tue, Jul 9, 2013 at 10:43 PM, Goswin von Brederlow <goswin-v-b@web.de>wrote:

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


> 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?
>
> I think you need higher kinded types, not GADTs. Haskell has them, for
example you can write code that only depends on the type class of "b"
(which is parameterized by "a"), and "b" has signature "* -> *" or
something like that.

[-- Attachment #2: Type: text/html, Size: 1713 bytes --]

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

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-09 20:43 Goswin von Brederlow
2013-07-09 20:52 ` Lukasz Stafiniak [this message]
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=CAJMfKEVVZem2rrSZ0GUz7LvwN8_nGWW9+zMzcB-zwesPrXqEjQ@mail.gmail.com \
    --to=lukstafi@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=goswin-v-b@web.de \
    /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).