From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: caml-list@inria.fr
Subject: [Caml-list] isn't this cheating?
Date: Fri, 26 Aug 2016 00:33:20 +0200 [thread overview]
Message-ID: <1472164400.6898.12.camel@gerd-stolpmann.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 1508 bytes --]
Hi,
just fixing up some GADT code. I came across this:
I have a module M with module type T:
module type T = sig
type p
val p_type : p Ztypes.ztype
val output : float -> p
end
Now, Ztypes.ztype is a GADT like
type _ ztype =
| Zstring : string ztype
| Zfloat : float ztype
| ...
In a function calling M.output I cannot assume that p=float unless I
check it explicitly. So I wrote
let f() =
let m_output =
match M.p_type with
| Ztypes.Zfloat -> (M.output : float -> float)
| _ -> assert false in
...
This doesn't type-check. Funnily, you can fix it by simply adding a
newtype to the function:
let f : type t = fun() ->
let m_output =
match M.p_type with
|
Ztypes.Zfloat -> (M.output : float -> float)
| _ -> assert false
in
...
It is just the presence of t that makes it type-check. This type is not in any way bound to the type parameter of ztype, and this is somewhat unexpected. From a user's perspective it is very comfy that the newtype works like a configuration switch for the type checker. Nevertheless, I wonder why it is like that.
Gerd
--
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de
My OCaml site: http://www.camlcity.org
Contact details: http://www.camlcity.org/contact.html
Company homepage: http://www.gerd-stolpmann.de
------------------------------------------------------------
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
next reply other threads:[~2016-08-25 22:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-25 22:33 Gerd Stolpmann [this message]
2016-08-25 22:35 ` Gerd Stolpmann
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=1472164400.6898.12.camel@gerd-stolpmann.de \
--to=info@gerd-stolpmann.de \
--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