From: Nicolas Boulay <nicolas@boulay.name>
To: David Allsopp <dra-news@metastack.com>
Cc: OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] problem to use gadt
Date: Sun, 15 Feb 2015 21:16:18 +0100 [thread overview]
Message-ID: <CAH+PdrAuJGyQFEDsA=ByYZ_i5FO9wwGkibADnHiPJVUp7zrL_A@mail.gmail.com> (raw)
In-Reply-To: <E51C5B015DBD1348A1D85763337FB6D9E9909404@Remus.metastack.local>
[-- Attachment #1: Type: text/plain, Size: 1711 bytes --]
2015-02-15 15:44 GMT+01:00 David Allsopp <dra-news@metastack.com>:
> Nicolas Boulay wrote:
> > I try to define my own type system using gadt.
> > But it seems that is complex to mix both type system : mine and the
> ocaml one.
> >
> > This tiny example did not compile:
> > type _ t =
> > | Or: _ t * _ t -> _ t
>
> Is this definitely what you mean - the "_" is not itself a distinct type
> variable so all three underscores in this instance are different types. cf
> the signature of the constructor:
>
> Or : 'b t * 'c -> 'a t
>
> > | Int : int t
> > | Float : float t
> >
> > let a = Or (Int, Float) (*is ok*)
>
> But again, does it have the type you mean, in this case 'a t?
>
> > let (||) a b = Or (a, b)
> > let aa = Int || Float (*Error: '_a t, contains type variable that cannot
> be generalized*)
>
> This is a consequence of the value restriction, I think.
>
> > Using an operator make a difference. But how to exprime "don't care"
> > if a choice between 2 types is not possible to be define. It could
> > be nice if "('a | 'b) t" worked :) Should i use normal sum type, and
> > make all type check by a function ?
>
> So you're saying that you don't care what the type of the two halves of an
> Or is? I don't see the problem you're trying to solve, but I wonder if your
> issue is that you need to pick a concrete type representation for the Or
> constructor. For example, does
>
> Or : _ t * _t -> unit t
>
> solve your problem?
>
>
Not really.
"t" is only a part of my complete type. It also have an "And"
| And : 'a t * 'a t -> 'a t
This "and" works well for "Float or Int" but not for "Or".
let aa = And ((Int || Float), Int) (*won't compile, int t != any t*)
> HTH,
>
>
> David
>
[-- Attachment #2: Type: text/html, Size: 2648 bytes --]
next prev parent reply other threads:[~2015-02-15 20:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-15 13:35 Nicolas Boulay
2015-02-15 14:44 ` David Allsopp
2015-02-15 20:16 ` Nicolas Boulay [this message]
2015-02-15 14:47 ` Gabriel Scherer
2015-02-15 20:17 ` Nicolas Boulay
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='CAH+PdrAuJGyQFEDsA=ByYZ_i5FO9wwGkibADnHiPJVUp7zrL_A@mail.gmail.com' \
--to=nicolas@boulay.name \
--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