caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Dmitry Bely <dmitry.bely@gmail.com>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] GADT memory representation
Date: Thu, 1 Dec 2016 13:26:30 +0300	[thread overview]
Message-ID: <CAMT7qiQN84ZKZSqrqpXF_9T1p9H9PzQ7koFV3QtbqGppRwagsQ@mail.gmail.com> (raw)
In-Reply-To: <E51C5B015DBD1348A1D85763337FB6D90135555A23@Remus.metastack.local>

On Thu, Dec 1, 2016 at 12:52 PM, David Allsopp <dra-news@metastack.com> wrote:
> Dmitry Bely wrote:
>> I need to access/modify GADT data from C glue code. What is their memory
>> representation? Is there any difference from ordinary sum types?
>
> It's the same - GADTs are "just" add a lot of clever typing stuff on top of a normal sum type - they don't affect the runtime operation of the code.

Thanks a lot for your explanation. Let me ask another dumb question
regarding GADTs. What should I do to make the following code
typecheck?

type sum = Int_ of int | Float_ of float;;
type _ gadt = Int : int -> int gadt | Float : float -> float gadt;;
let convert (type el) v : el gadt = match v with  Int_ i -> Int i |
Float_ f -> Float f;;

Characters 61-66:
   let convert (type el) v : el gadt = match v with  Int_ i -> Int i |
Float_ f -> Float f;;
                                                               ^^^^^
Error: This expression has type int gadt
       but an expression was expected of type el gadt
       Type int is not compatible with type el

>> Unfortunately OCaml manual doesn't even mention GADTs in section
>> "Interfacing C with OCaml".
>
> That's worth a GPR/Mantis issue.

Yes, I'll submit one.

- Dmitry Bely

  reply	other threads:[~2016-12-01 10:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-01  9:22 Dmitry Bely
2016-12-01  9:52 ` David Allsopp
2016-12-01 10:26   ` Dmitry Bely [this message]
2016-12-01 11:51   ` Alain Frisch
2016-12-01 14:12     ` octachron
2016-12-01 14:32     ` Dmitry Bely
2016-12-01 14:50       ` Gabriel Scherer
2016-12-01 15:21     ` Josh Berdine
2016-12-03 14:50     ` David Allsopp

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=CAMT7qiQN84ZKZSqrqpXF_9T1p9H9PzQ7koFV3QtbqGppRwagsQ@mail.gmail.com \
    --to=dmitry.bely@gmail.com \
    --cc=caml-list@inria.fr \
    /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).