From: "Daniel Bünzli" <daniel.buenzli@erratique.ch>
To: "Milan Stanojević" <milanst@gmail.com>
Cc: Caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] GADT existential escape
Date: Thu, 19 Mar 2015 11:44:46 +0100 [thread overview]
Message-ID: <A9833AA6DB2C40058D2E66B6A381E599@erratique.ch> (raw)
In-Reply-To: <CAKR7PS_fFML9gvqF1Zr0qa+2uEMUg4FQfp2f9gXuhN1Ee7_n=A@mail.gmail.com>
Le jeudi, 19 mars 2015 à 02:27, Milan Stanojević a écrit :
> This is doable in OCaml.
Cool, a new trick. My understanding of this is basically to apply to types the same idea as Univ by representing them as a first class module.
However are you sure your example compiles (tried to check, but Core fails on me in the toplevel) ? Trying the following [1] self-contained implementation of the idea [1] the compiler still complains about escaping types.
> Note that Univ was possible in OCaml even before first-class
> modules, GADTs and extensible types (which are all used in Type_equal)
Yes, see http://alan.petitepomme.net/cwn/2010.02.09.html#1 if you are interested how.
Thanks,
Daniel
[1]
module Key = struct
type _ t = ..
end
module type W = sig
type t
type _ Key.t += Key : t Key.t
end
type 'a witness = (module W with type t = 'a)
let witness () (type s) =
let module M = struct
type t = s
type _ Key.t += Key : t Key.t
end
in
(module M : W with type t = s)
type ('a, 'b) eq = Eq : ('a, 'a) eq
let eq (type r) (type s) (r : r witness) (s : s witness)
: (r, s) eq option
=
let module R = (val r : W with type t = r) in
let module S = (val s : W with type t = s) in
match R.Key with
| S.Key -> Some Eq
| _ -> None
type 'a key = 'a witness
type binding = B : 'a key * 'a -> binding
type dict = binding list
let lookup : dict -> 'a key -> 'a option = fun d k ->
let rec find = function
| [] -> None
| B (k', v) :: bs ->
match eq k k' with
| None -> find bs
| Some Eq -> Some v
in
find d
next prev parent reply other threads:[~2015-03-19 10:45 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ć
2015-03-19 10:44 ` Daniel Bünzli [this message]
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=A9833AA6DB2C40058D2E66B6A381E599@erratique.ch \
--to=daniel.buenzli@erratique.ch \
--cc=caml-list@inria.fr \
--cc=milanst@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