From: "Jon Harrop" <jon@ffconsultancy.com>
To: "'Jacques Garrigue'" <garrigue@math.nagoya-u.ac.jp>,
"'OCaML List Mailing'" <caml-list@inria.fr>
Subject: RE: [Caml-list] ocaml considered dangerous
Date: Sat, 18 Jan 2014 00:39:24 -0000 [thread overview]
Message-ID: <02b301cf13e5$bdd11af0$397350d0$@ffconsultancy.com> (raw)
In-Reply-To: <0290505B-A21A-4A05-A1C9-4C5F765DFEB5@math.nagoya-u.ac.jp>
> 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.
Just curious: is that a drop-in replacement?
Cheers,
Jon.
-----Original Message-----
From: caml-list-request@inria.fr [mailto:caml-list-request@inria.fr] On Behalf Of Jacques Garrigue
Sent: 17 January 2014 02:39
To: OCaML List Mailing
Subject: Re: [Caml-list] ocaml considered dangerous
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
--
Caml-list mailing list. Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs=
next prev parent reply other threads:[~2014-01-18 0: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
2014-01-17 9:01 ` Gabriel Scherer
2014-01-18 0:39 ` Jon Harrop [this message]
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='02b301cf13e5$bdd11af0$397350d0$@ffconsultancy.com' \
--to=jon@ffconsultancy.com \
--cc=caml-list@inria.fr \
--cc=garrigue@math.nagoya-u.ac.jp \
/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