From: Guillaume Yziquel <guillaume.yziquel@citycable.ch>
To: Alain Frisch <alain@frisch.fr>
Cc: David Allsopp <dra-news@metastack.com>, caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Re: module typing issue
Date: Mon, 28 Mar 2011 14:39:10 +0200 [thread overview]
Message-ID: <20110328123910.GC20598@localhost> (raw)
In-Reply-To: <4D907DD6.2030507@frisch.fr>
Le Monday 28 Mar 2011 à 14:23:50 (+0200), Alain Frisch a écrit :
> On 03/28/2011 01:58 PM, Guillaume Yziquel wrote:
> >Yes an no. From a type inference perspective, that's right. However, you
> >can already do such pattern matching on private row types for variant
> >types.
> >
> >module X : sig
> > type t = private [< `A ]
> > val x : t
> >end = struct
> > type t = [ `A ]
> > let x = `A
> >end
> >
> >match X.x with `A -> ()
> >
> >and the X.x is correctly unified with `A. So the type inference issue is
> >solved in this case.
>
> Private row types are not the same as private type abbreviations.
> The syntax might be a source of confusion here, but the keyword
> "private" really means three different things:
Yes. I just find it too bad that the distinction between these three
different 'private' types is so neat.
> - Private type declarations: constructors/labels are available for
> deconstructing values (pattern matching, dot notation), not for
> building values.
That's where I'd like type t = private int to stand at times. Having it
as a private type abbreviation is sometimes too strong.
> - Private type abbreviations (where the abbreviated type is not an
> object type or a polymorphic variant type): the behavior is very
> much the same as an abstract type, except that the abbreviation is a
> subtype of the abbreviated type (and the compiler can use the
> concrete type to choose a runtime representation of -- e.g. for
> records of floats -- and to trigger optimizations).
Yes. I'm just sad that when you have predefined pattern-matching way to
deal with a type (such as strings or ints), these private type
abbreviations drop the deconstructing features of private type
declarations.
> - Private row types: you can think of the 'private' annotation as a
> way to name (as an abstract type) the implicit row type variable of
> the abbreviated type. There is no hiding as for type abbreviation
> and no access control as for private type declarations.
Yes. And in a signature, you can replace them with the 'with type :='
construct. This is again different, and also handy.
> The syntax for private type abbreviation and private row types is
> the same; they are distinguished only in the type-checker. As far as
> I know, there is no way to create a private type abbreviation on a
> object or variant type.
Except than aliasing the object or variant type to another type and
doing a private type abbreviation on the alias.
> Alain
--
Guillaume Yziquel
next prev parent reply other threads:[~2011-03-28 12:39 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-25 8:34 [Caml-list] " Joel Reymont
2011-03-25 8:44 ` [Caml-list] " Joel Reymont
2011-03-25 14:17 ` Joel Reymont
2011-03-25 15:46 ` Andreas Rossberg
2011-03-25 15:57 ` Joel Reymont
2011-03-25 16:04 ` Andreas Rossberg
2011-03-25 16:42 ` Guillaume Yziquel
2011-03-25 16:59 ` Andreas Rossberg
2011-03-25 19:01 ` Guillaume Yziquel
2011-03-25 19:13 ` Andreas Rossberg
2011-03-28 7:53 ` Alain Frisch
2011-03-28 10:33 ` Guillaume Yziquel
2011-03-28 11:29 ` David Allsopp
2011-03-28 11:58 ` Guillaume Yziquel
2011-03-28 12:11 ` David Allsopp
2011-03-28 12:29 ` Guillaume Yziquel
2011-03-28 12:23 ` Alain Frisch
2011-03-28 12:39 ` Guillaume Yziquel [this message]
2011-03-28 11:32 ` David Allsopp
2011-03-28 12:02 ` Guillaume Yziquel
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=20110328123910.GC20598@localhost \
--to=guillaume.yziquel@citycable.ch \
--cc=alain@frisch.fr \
--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