From: Dawid Toton <d0@wp.pl>
To: caml-list <caml-list@yquem.inria.fr>
Subject: Re: Phantom types
Date: Mon, 17 May 2010 18:00:35 +0200 [thread overview]
Message-ID: <4BF16823.6010801@wp.pl> (raw)
In-Reply-To: <AANLkTilqG13QE_3iAcxHXMD99aBZk6HYceKkfN0W2EVT@mail.gmail.com>
> type 'a t = {l: float}
>
> Any thoughts ?
I think the crucial question is when new record types are born. Here is
my opinion:
The "=" sign in the above type mapping definition is what I would call
"delayed binding". "Early binding" would be equivalent to
type tmp = {lab : float}
type 'a s = tmp
(evaluate the right-hand side first, then define the mapping).
The "early binding" creates only one record type, so lab becomes
ordinary record label.
In the given example of the "delayed binding" the t becomes a machine
producing new record types.
Hence, the identifier l is not an ordinary record label. It is shared by
whole family of record types. We can see it this way:
# type 'a t = { la : float } ;;
type 'a t = { la : float; }
# {la = 0.};;
- : 'a t = {la = 0.}
So OCaml interpreter doesn't know the exact type of the last expression,
but it is clever enough to give it a generalized type.
We can use la to construct records of incompatible types:
# type 'a t = { la : float } ;;
type 'a t = { la : float; }
# let yy = ({la = 0.} : int t) ;;
val yy : int t = {la = 0.}
# let xx = ({la = 0.} : string t);;
val xx : string t = {la = 0.}
# xx = yy;;
Error: This expression has type int t but an expression was expected of type
string t
I suppose my jargon may be not mainstream, apologies.
Dawid
next prev parent reply other threads:[~2010-05-17 16:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-17 14:59 Thomas Braibant
2010-05-17 15:14 ` [Caml-list] Phantom types [NC] Rabih CHAAR
2010-05-17 15:19 ` Philippe Veber
2010-05-17 16:00 ` Dawid Toton [this message]
2010-05-17 16:37 ` [Caml-list] Phantom types Goswin von Brederlow
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=4BF16823.6010801@wp.pl \
--to=d0@wp.pl \
--cc=caml-list@yquem.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