From: "Milan Stanojević" <milanst@gmail.com>
To: "Daniel Bünzli" <daniel.buenzli@erratique.ch>
Cc: Caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] GADT existential escape
Date: Wed, 18 Mar 2015 21:27:09 -0400 [thread overview]
Message-ID: <CAKR7PS_fFML9gvqF1Zr0qa+2uEMUg4FQfp2f9gXuhN1Ee7_n=A@mail.gmail.com> (raw)
In-Reply-To: <596DAEC11B474882835CEA10AAACE35E@erratique.ch>
This is doable in OCaml.
Core has one possible implementation.
https://github.com/janestreet/core_kernel/blob/master/lib/type_equal.mli#L171
type 'a key = 'a Type_equal.Id.t
let lookup dict key =
List.find_map disct ~f:(function
| B (key', a) ->
match Type_equal.Id.same_witness key key' with
| None -> None
| Some T -> Some a)
;;
You can also check out Univ and Univ_map modules in Core.
Note that Univ was possible in OCaml even before first-class
modules, GADTs and extensible types (which are all used in Type_equal)
https://blogs.janestreet.com/a-universal-type/
On Wed, Mar 18, 2015 at 9:07 PM, Daniel Bünzli
<daniel.buenzli@erratique.ch> wrote:
> Le jeudi, 19 mars 2015 à 01:39, Milan Stanojević a écrit :
>> Can you give some hypothetical example code ?
> type 'a key = ?
> type binding = B : 'a key * 'a -> binding
> type dict = binding list
> let lookup : dict -> 'a key -> 'a option = fun d k -> ?
>
> Is it possible to specify a `'a key` type that allows `lookup` (with the obvious semantics) to be written ? This is trivial to achieve with a universal type, see http://mlton.org/PropertyList
>
> Best,
>
> Daniel
>
>
next prev parent reply other threads:[~2015-03-19 1:27 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-19 0:29 Daniel Bünzli
2015-03-19 0:39 ` Milan Stanojević
2015-03-19 1:07 ` Daniel Bünzli
2015-03-19 1:27 ` Milan Stanojević [this message]
2015-03-19 10:44 ` Daniel Bünzli
2015-03-19 11:02 ` Jeremy Yallop
2015-03-19 11:34 ` Daniel Bünzli
2015-03-19 13:22 ` Daniel Bünzli
2015-03-19 16:46 ` Milan Stanojević
2015-03-19 17:14 ` Daniel Bünzli
2015-03-19 17:15 ` Frédéric Bour
2015-03-19 17:22 ` Milan Stanojević
2015-03-19 17:41 ` Jeremy Yallop
2015-03-19 18:29 ` Alain Frisch
2015-03-19 16:31 ` Milan Stanojević
2015-03-19 11:05 ` Jeremie Dimino
2015-03-19 11:34 ` Daniel Bünzli
2015-03-19 11:59 ` Jeremie Dimino
2015-03-20 13:50 ` Yaron Minsky
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='CAKR7PS_fFML9gvqF1Zr0qa+2uEMUg4FQfp2f9gXuhN1Ee7_n=A@mail.gmail.com' \
--to=milanst@gmail.com \
--cc=caml-list@inria.fr \
--cc=daniel.buenzli@erratique.ch \
/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