caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Nicolas Boulay <nicolas@boulay.name>
Cc: OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] problem to use gadt
Date: Sun, 15 Feb 2015 15:47:03 +0100	[thread overview]
Message-ID: <CAPFanBEDAkRLnuNNOmdyJDVHbNkKaDG32NTOE_rE3C=EwJpcjA@mail.gmail.com> (raw)
In-Reply-To: <CAH+PdrC=G0Bd+Pw6b9LwE9Fvo4Sz5ow8ESvUBqPbgsa_tvJ1Aw@mail.gmail.com>

The typing rule for Or is rather weird: any type can be used as the
result type, which is non-standard. You could define a dummy type
"any"

  type any = Any

  [...]

  | Or : _ t * _ t -> any t

and the output type of Or wouldn't be polymorphic anymore, so the
value restriction (
http://caml.inria.fr/resources/doc/faq/core.en.html#weak-type-variables
) wouldn't be a problem anymore.

On Sun, Feb 15, 2015 at 2:35 PM, Nicolas Boulay <nicolas@boulay.name> 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
>  | Int : int t
>  | Float : float t
>
> let a = Or (Int, Float)  (*is ok*)
>
> let (||)  a b = Or (a, b)
>
> let aa = Int || Float (*Error: '_a t, contains type variable that cannot be
> generalized*)
>
> 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 ?
>
> Nicolas Boulay

  parent reply	other threads:[~2015-02-15 14:47 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
2015-02-15 14:47 ` Gabriel Scherer [this message]
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='CAPFanBEDAkRLnuNNOmdyJDVHbNkKaDG32NTOE_rE3C=EwJpcjA@mail.gmail.com' \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=nicolas@boulay.name \
    /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).