caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: lukstafi@gmail.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Fwd: "ocaml_beginners"::[] Trouble combining polymorphic classes and polymorphic methods
Date: Wed, 28 Feb 2007 10:34:03 +0900 (JST)	[thread overview]
Message-ID: <20070228.103403.105433774.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <4a708d20702271718r3fa74211jbf81372bc9fb8b79@mail.gmail.com>

From: "Lukasz Stafiniak" <lukstafi@gmail.com>
> Thank you for the answer. Let's play the dual of this game:
> 
> # type 'a sty = [`Foo of (int * 'a) sty | `Bar];;
> Characters 4-45:
>   type 'a sty = [`Foo of (int * 'a) sty | `Bar];;
>       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> In the definition of sty, type (int * 'a) sty should be 'a sty
> # type 'a nty = Foo of (int * 'a) nty | Bar;;
> type 'a nty = Foo of (int * 'a) nty | Bar

Indeed, this is to be expected. Again, if one needs both polymorphic
variants and irregular types, it is possible to combine both, but not
very natural.

> (I wonder if this is the reason when people rant that structural types
> are a weaker form of type control... ;) Recently I've started using
> closed polymorphic variant types to build subtyping hierarchies and
> this gives more type control to me, I think.)

For your first point, I don't think so. Irregular types are quite rare
in practice, though they arise rather naturally when combining objects
and polymorphism. What some people do not like about structural types
is that they do not "brand" types: you can define the same type
elsewhere, possibly with a different intended meaning, and the
compiler will not distinguish between the two. This type equality also
means that you cannot rely on type identity for privacy features: this
is the reason why ocaml private methods are not like Java.
But on the other hand, in many cases you precisely want this equality.

Jacques Garrigue


  reply	other threads:[~2007-02-28  1:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <301730110702251747y72ae9fbdqd33bd8d08293cbe3@mail.gmail.com>
2007-02-27 21:22 ` Geoffrey Romer
2007-02-28  0:23   ` [Caml-list] " Jacques Garrigue
2007-02-28  1:18     ` Lukasz Stafiniak
2007-02-28  1:34       ` Jacques Garrigue [this message]
2007-02-28  1:57         ` skaller
2007-02-28  3:23           ` Daniel Bünzli
2007-02-28  4:01             ` Jacques Garrigue
2007-02-28  5:09               ` skaller
2007-02-28 13:47               ` Daniel Bünzli

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=20070228.103403.105433774.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=lukstafi@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).