From: Kuba Ober <ober.14@osu.edu>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] different records, same field name?
Date: Mon, 3 Mar 2008 14:32:02 -0500 [thread overview]
Message-ID: <200803031432.03002.ober.14@osu.edu> (raw)
In-Reply-To: <47CC2D9F.6050109@starynkevitch.net>
On Monday 03 March 2008, Basile STARYNKEVITCH wrote:
> mfmorss@aep.com wrote:
> > In any case, is it possible to define and use different types of records,
> > which nevertheless share some field names? I have had difficulty doing
> > this in the toplevel.
>
> It is not possible, for a simple reason:
>
> Suppose you have two record type tr1 & tr2 sharing a common field name f
>
> type tr1 = { f : int; f1 : string }
>
> type tr2 = { f2 : float; f: int }
>
> Then the compiler won't be able to infer the type of function ff
> retrieving this field f
>
> let ff x = x.f
>
> So the requirement that each field name is different is the price to pay
> to have type inference.
I think that type inference in OCaml sometimes gets in the way of other
language features. I'd much rather see OCaml go in a direction where type
inference is performed on "as far as it can go" basis.
In the cited example, if the compiler couldn't infer the type, it should
simply remind the user to use explicit type as appropriate in such case.
While I do admit that this may cause some "silly" behavior, where changes in
unrelated code can cause compile errors elsewhere, this should be naturally
shielded by module boundaries. So, as far as I can see, it wouldn't suddenly
break precompiled modules, at least.
Cheers, Kuba
next prev parent reply other threads:[~2008-03-03 19:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-03 16:51 mfmorss
2008-03-03 16:53 ` [Caml-list] " Jon Harrop
2008-03-03 16:55 ` Basile STARYNKEVITCH
2008-03-03 19:32 ` Kuba Ober [this message]
2008-03-03 21:04 ` Michael Wohlwend
2008-03-03 22:29 ` Jon Harrop
2008-03-03 18:45 ` DooMeeR
2008-03-04 9:52 ` Berke Durak
2008-03-04 10:25 ` David Teller
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=200803031432.03002.ober.14@osu.edu \
--to=ober.14@osu.edu \
--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