From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Bob Zhang <bobzhang1988@gmail.com>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Robust left to right flow for record disambiguation
Date: Thu, 24 Oct 2013 10:40:41 +0900 [thread overview]
Message-ID: <C34DDC63-35B3-43EA-8361-13160A4A849E@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <CANcqPu70B1kOEtZgiNH1jxBTAUoo9dyp6Dt9hKb7OXwa7f1Wig@mail.gmail.com>
On 2013/10/24, at 5:52, Bob Zhang <bobzhang1988@gmail.com> wrote:
> Record disambiguation is a practical feature, it helps a lot in
> writing open-free code.
> In practice, I found it is a bit limited, below is two scenarios
> that the compiler can not infer in a correct way, will this be
> improved in the future by any chance?
> From the user's point of view, annotating the toplevel is quite
> acceptable, maybe the typechecker could take the type-annotation as a
> higher priority.
> ---
> 1.
> let f (ls:t) =
> ls |> List.map (fun x -> x.loc) (* cannot inferred x.loc*)
> 2.
> type t = {loc:string}
> type v = {loc:string; x:int}
> type u = [`Key of t]
> let f (u:t) =
> match u with
> | `Key {loc} -> loc (* does not compile *)
Case 1 would require a new specification of how type propagation works.
In particular, propagating from an argument to another argument.
For this reason, the probability that it gets done is low.
(I know that F# handles this case in a special way, but do we want to introduce
a special case just for |> ?)
Case 2 seems more reasonable (after replacing (u:t) by (u:u)).
In particular,
let f (u:u) =
match u with `Key loc -> loc.loc
already works, so it seems strange that the pattern-matching version doesn't.
Jacques
next prev parent reply other threads:[~2013-10-24 1:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-23 20:52 Bob Zhang
2013-10-24 1:40 ` Jacques Garrigue [this message]
2013-10-24 3:11 ` Bob Zhang
2013-10-25 9:20 ` Alain Frisch
2013-10-25 11:27 ` Didier Remy
2013-10-25 12:39 ` Alain Frisch
2013-10-25 13:06 ` Wojciech Meyer
2013-10-26 6:05 ` 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=C34DDC63-35B3-43EA-8361-13160A4A849E@math.nagoya-u.ac.jp \
--to=garrigue@math.nagoya-u.ac.jp \
--cc=bobzhang1988@gmail.com \
--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