caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alain Frisch <alain@frisch.fr>
To: Lukasz Stafiniak <lukstafi@gmail.com>,
	 Goswin von Brederlow <goswin-v-b@web.de>
Cc: Caml <caml-list@inria.fr>
Subject: Re: [Caml-list] GADTs and associative container
Date: Wed, 10 Jul 2013 12:16:54 +0200	[thread overview]
Message-ID: <51DD3496.2020304@frisch.fr> (raw)
In-Reply-To: <CAJMfKEVVZem2rrSZ0GUz7LvwN8_nGWW9+zMzcB-zwesPrXqEjQ@mail.gmail.com>

Hi,

This thread might of interest to you:
https://sympa.inria.fr/sympa/arc/caml-list/2013-02/msg00037.html


Alain


On 07/09/2013 10:52 PM, Lukasz Stafiniak wrote:
> On Tue, Jul 9, 2013 at 10:43 PM, Goswin von Brederlow <goswin-v-b@web.de
> <mailto: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.


  parent reply	other threads:[~2013-07-10 10:16 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
2013-07-10  9:52   ` Leo White
2013-07-10 10:16   ` Alain Frisch [this message]
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=51DD3496.2020304@frisch.fr \
    --to=alain@frisch.fr \
    --cc=caml-list@inria.fr \
    --cc=goswin-v-b@web.de \
    --cc=lukstafi@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).