caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: OCaML List Mailing <caml-list@inria.fr>
Subject: Re: [Caml-list] ocaml considered dangerous
Date: Fri, 17 Jan 2014 11:38:52 +0900	[thread overview]
Message-ID: <0290505B-A21A-4A05-A1C9-4C5F765DFEB5@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <2112632769.281907.1389913202532.open-xchange@communicator.strato.de>

Let me repost here the answer I sent to Jurgen on the developer’s list.
I wonder why he posted simultaneously to both lists.


First remark, rather than posting such a (broken) link, it would be better
to file a report in the bug tracking system at
	http://caml.inria.fr/mantis/

Second, I’ve read your post (fortunately going to  http://www.pfitzenmaier.de/ let
me access it), and this appears to be a misunderstanding of the meaning of type
annotations in OCaml.
Namely, while type annotations in signatures are universally quantified
(which is why ‘a list = forall ‘a. ‘a list is more general than int list, and your first
example is not accepted), type annotations in expressions are existentially
quantified, i.e. the variables may be instantiated, and as a result your second
example is accepted (int list ref is an instance of ‘a list ref).
Same thing in your third example: the annotation ‘a list -> ‘a just means that
there should be some type a such that get_sum has type a list -> a, and here
that type is int.

If you want annotations in expressions to be universally quantified, you must be
explicit:

 let get_sum : 'a. 'a list -> 'a = A.sum

This one requires get_sum to be polymorphic, and will report an error.

Of course changing line 28 in includecore.ml solves nothing, since this line is
correct from the beginning.

Your examples with polymorphic variants are again a misunderstanding of
how typing works. Namely, in OCaml subtyping is always explicit.
So in F1 you should write:
	let get_count :> [`A] list -> 'a = A.count
(Note that in some case you also need to give the original type of the expression
for subtyping to work properly. Here this is not needed because the target type is
simple enough)

For your frightening discoveries, the definition of ty0 is on line 499… maybe too close
to see.

Last, the current implementation of Printf relies heavily on Obj.magic, which means
that you cannot tell much about the typing by what you see inside the implementation.
To my best knowledge, the exported interface is type safe.
By the way, there is now an implementation of Printf that avoids most of the Obj.magic
by using GADTs. It should be merged soon.

Finally I would suggest not to post such a blog before you discuss the problems
you encountered with somebody (not necessarily the developers, just somebody
knowledgeable enough in OCaml) as this may confuse people in a useless way.
This would also have avoided you to part from OCaml for inexistent reasons...

Best regards,

Jacques Garrigue

  parent reply	other threads:[~2014-01-17  2:39 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-16 23:00 Jürgen Pfitzenmaier
2014-01-16 23:27 ` Milan Stanojević
2014-01-16 23:33 ` Daniel Bünzli
2014-01-17  0:43 ` Nicolas Braud-Santoni
2014-01-20 10:07   ` Goswin von Brederlow
2014-01-17  2:12 ` Jeff Meister
2014-01-17  2:38 ` Jacques Garrigue [this message]
2014-01-17  9:01   ` Gabriel Scherer
2014-01-18  0:39   ` Jon Harrop
2014-01-18  2:22     ` Jeremy Yallop
2014-01-18  7:04       ` Gabriel Scherer
2014-01-18  9:11         ` David Allsopp
2014-01-18  9:28           ` Gabriel Scherer
2014-01-18  9:43             ` David Allsopp
2014-01-18  9:59               ` Gabriel Scherer
2014-01-19  6:09         ` oleg

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=0290505B-A21A-4A05-A1C9-4C5F765DFEB5@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    /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).