caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Roberto Di Cosmo <roberto@dicosmo.org>
To: Jonathan Protzenko <jonathan.protzenko@gmail.com>
Cc: Ivan Gotovchits <ivg@ieee.org>,
	Andreas Rossberg <rossberg@mpi-sws.org>,
	Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>,
	OCaML List Mailing <caml-list@inria.fr>
Subject: Re: [Caml-list] Equality between abstract type definitions
Date: Fri, 25 Oct 2013 15:20:32 +0200	[thread overview]
Message-ID: <20131025132032.GB12951@voyager> (raw)
In-Reply-To: <526A6800.9020501@gmail.com>

Hi Jonathan,
   I beg to disagree

On Fri, Oct 25, 2013 at 02:45:52PM +0200, Jonathan Protzenko wrote:
> You should also remember that the top-level, which is what most
> beginners use, also favors the confusion.
> 
> # let f x = x;;
> val f : 'a -> 'a = <fun>

OCaml is telling you: hey, your code is so generic that I can give it
the type 'a -> 'a, you got a polymorphic function!

> # let f : 'a -> 'a = fun x -> x + 1;;
> val f : int -> int = <fun>
> 

Here you are telling OCaml: 
 look, I'd like to see f as having type 'a -> 'a, what do you think?

And OCaml tells you: sorry sir, the best I can give you is int -> int

> What OCaml is actually telling you is: "this function has type 'a -> 'a,
> but if you write 'a -> 'a yourself, I'm going to give it a totally
> different meaning".
> 
> ~ jonathan

The point on which I agree is that if we leave these annotations in
the code, they may end up being read as specifications by whomever
looks at the sources alone, and this may lead to confusion.

But to spot such issues we do not need to change the syntax and semantics of 
type annotations, it would be enough to have yet another warning
that informs us that the type annotations have been instanciated...
something like

# let f : 'a -> 'a = fun x -> x + 1;;
           _______
Warning 66: the user provided type constraint is too general:
variable 'a has been instanciated to type int
val f : int -> int = <fun>

--
Roberto

P.S.: I will not feed the troll any longer though, time to
get back to work :-)


  reply	other threads:[~2013-10-25 13:20 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-24 22:57 Peter Frey
2013-10-24 23:23 ` Jacques Garrigue
2013-10-25  6:44   ` Andreas Rossberg
2013-10-25  8:29     ` Roberto Di Cosmo
2013-10-25  9:59       ` Ivan Gotovchits
2013-10-25 11:09         ` Gabriel Scherer
2013-10-25 14:24           ` Andreas Rossberg
2013-10-25 20:32             ` Yaron Minsky
2013-10-25 20:44               ` Jacques Le Normand
2013-10-26  1:08                 ` Norman Hardy
2013-10-26  5:28                   ` Jacques Garrigue
2013-10-27 12:16               ` Andreas Rossberg
2013-10-27 12:56                 ` Yaron Minsky
2013-10-27 14:28                   ` Gabriel Scherer
2013-10-27 14:43                     ` Yaron Minsky
2013-10-27 15:25                       ` Gabriel Scherer
2013-10-27 15:41                         ` Yaron Minsky
2013-10-25 12:35         ` Roberto Di Cosmo
2013-10-25 12:45           ` Jonathan Protzenko
2013-10-25 13:20             ` Roberto Di Cosmo [this message]
2013-10-25 14:03       ` Andreas Rossberg
2013-10-26  9:07         ` oleg
2013-10-26 14:11           ` Didier Remy
2013-10-26 17:32         ` Didier Remy
2013-10-27 12:07           ` Andreas Rossberg
2013-10-27 14:10             ` Roberto Di Cosmo
2013-10-28  3:30     ` Jacques Garrigue

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=20131025132032.GB12951@voyager \
    --to=roberto@dicosmo.org \
    --cc=caml-list@inria.fr \
    --cc=garrigue@math.nagoya-u.ac.jp \
    --cc=ivg@ieee.org \
    --cc=jonathan.protzenko@gmail.com \
    --cc=rossberg@mpi-sws.org \
    /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).