caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alain Frisch <alain@frisch.fr>
To: David Allsopp <dra-news@metastack.com>,  OCaml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Mixing two GADTs
Date: Mon, 01 Jul 2013 09:50:10 +0200	[thread overview]
Message-ID: <51D134B2.70800@frisch.fr> (raw)
In-Reply-To: <001001ce762e$1bedde30$53c99a90$@metastack.com>

On 07/01/2013 09:39 AM, David Allsopp wrote:
> Obviously, I need type annotations for f and retr. I'd tried:
>
> let get2 : type s . s foo -> s = fun attr ->
>    let x : type t . (t -> s) * t bar =
>      match attr with
>        A -> (int_of_string, Z)
>      | B -> (string_of_float, Y)
>      | C -> ((=) 1, X)
>    in
>      let (f, retr) = x
>      in
>        f (g retr)

What you need is an existential quantification ("there exists some t 
such that x has type (t -> s) * t bar").  You can do this by wrapping 
the tuple in a third GADT:

type 's baz = T: ('t -> 's) * 't bar -> 's baz

let get2 : type s . s foo -> s = fun attr ->
   let x : s baz =
     match attr with
     | A -> T (int_of_string, Z)
     | B -> T (string_of_float, Y)
     | C -> T ((=) 1, X)
   in
   let (T (f, retr)) = x in
   f (g retr)


-- Alain

      reply	other threads:[~2013-07-01  7:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-01  7:39 David Allsopp
2013-07-01  7:50 ` Alain Frisch [this message]

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=51D134B2.70800@frisch.fr \
    --to=alain@frisch.fr \
    --cc=caml-list@inria.fr \
    --cc=dra-news@metastack.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).