caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: philippe.veber@googlemail.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Closed variants, type constraints and module signature
Date: Mon, 17 May 2010 23:31:46 +0900 (JST)	[thread overview]
Message-ID: <20100517.233146.139556665.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <AANLkTikYr_BuPhpszSmWQZIB7tqcf3Cck9HbYGumvdux@mail.gmail.com>

From: Philippe Veber <philippe.veber@googlemail.com>
>> Constrained types have their uses,
> 
> which are, in brief ? Now I can't see a typical use for closed polymorphic
> variant types (I mean types of the form 'a t constraint 'a = [< ... ])

A typical use would be for objects, particularly when representing
virtual types (see the advanced part of the tutorial, in the reference
manual).
Another application is to use a record notation for type variables:

  type 'r t = .... constraint 'r = < env:'env; loc:'loc; typ:'typ; .. >
 
This way you can share multiple type parameters at once, and even
allow transparent addition of new parameters. This was not the
original goal of constraints, but I find it handy.

I have no immediate example with polymorphic variants, but your
arguments about scalability are valid: in some cases, constraints
allow more compact types. But at a cost.

>> but I find them often confusing as
>> the type variable you write is not really a type variable.
>>
> why isn't it the case ? Aren't they simply type variables restricted to a
> finite number of types ?

Yes they are constrained type variables.
But the problem is that the constraint is left implicit.

For instance, if somewhere you have defined

  type 'a t constraint 'a = [< `a | `b]

and inside an interface you write

  val f : 'a t -> int

the real meaning is

  val f : [< `a | `b] t -> int

I.e., you are hiding something.

This is not the same thing as type abbreviations, because constraints
are applied from the outside, while abbreviations just have to be
expanded.

Jacques Garrigue


      reply	other threads:[~2010-05-17 14:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-14 15:17 Philippe Veber
2010-05-14 15:49 ` [Caml-list] " Jacques Garrigue
2010-05-14 21:33   ` Philippe Veber
2010-05-15  0:54     ` Jacques Garrigue
2010-05-17 11:56       ` Philippe Veber
2010-05-17 14:31         ` Jacques Garrigue [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=20100517.233146.139556665.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=philippe.veber@googlemail.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).