caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Markus Mottl <markus.mottl@gmail.com>
Cc: OCaml List <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Late adding of type variable constraints
Date: Fri, 4 Sep 2015 15:19:20 -0700	[thread overview]
Message-ID: <B4CA33D4-108C-4308-9A4B-4D336DAF5811@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <CAP_800pEYkpDn9yXgnuCkdVjHND1yAvGPwcUsLD0mxq0NF9DJw@mail.gmail.com>

On 2015/09/04 13:28, Markus Mottl <markus.mottl@gmail.com> wrote:
> 
> Hi,
> 
> I wonder whether there is a way to add constraints to type variables
> in signatures after the signature was defined.  E.g.:
> 
> ---
> module type S = sig
>  type 'a t
>  type ('a, 'b) mappers
> 
>  val map : ('a, 'b) mappers -> 'a t -> 'b t
> end
> 
> module type T = sig
>  type 'a t constraint 'a = unit  (* whatever *)
>  include S with type 'a t := 'a t
> end
> ---
> 
> The above will fail, because 'a has additional constraints for type
> "t" in signature "T".  If I write instead e.g. "type 'a t = 'a list",
> this will work and also constrain the signature to something narrower.
> What makes constraints on polymorphic variables special here?

Consider this signature:

module type S = sig
  type 'a t
  type 'a u = U of 'a t constraint 'a = < m: int; .. >
end

Now the signature
   S with type 'a constraint 'a t = unit
is ill-typed, but to see it you must type-check again all of its contents
(not just the definition of t).

This is the reason you cannot do that.

Jacques Garrigue

  reply	other threads:[~2015-09-04 22:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-04 20:28 Markus Mottl
2015-09-04 22:19 ` Jacques Garrigue [this message]
2015-09-04 23:58   ` Markus Mottl
2015-09-07 18:33     ` Mikhail Mandrykin
2015-09-09 14:00       ` Markus Mottl
2015-09-09 19:28         ` Mikhail Mandrykin
2015-09-11 15:56           ` Markus Mottl
2015-09-11 16:24             ` Mikhail Mandrykin

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=B4CA33D4-108C-4308-9A4B-4D336DAF5811@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@yquem.inria.fr \
    --cc=markus.mottl@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;
as well as URLs for NNTP newsgroup(s).