From: Yoann Padioleau <padator@wanadoo.fr>
To: Goswin von Brederlow <goswin-v-b@web.de>
Cc: Yoann Padioleau <padator@wanadoo.fr>, caml-list@inria.fr
Subject: Re: [Caml-list] pattern matching and records vs tuples
Date: Tue, 14 Apr 2009 11:58:26 -0500 [thread overview]
Message-ID: <87myajuq8d.fsf@aryx.cs.uiuc.edu> (raw)
In-Reply-To: <87tz4ryyrb.fsf@frosties.localdomain> (Goswin von Brederlow's message of "Tue\, 14 Apr 2009 18\:40\:40 +0200")
Goswin von Brederlow <goswin-v-b@web.de> writes:
> Yoann Padioleau <padator@wanadoo.fr> writes:
>
>> Hi,
>>
>> I've found that while records provide advantages over tuples,
>> they also have disadvantages when it comes to evolution issues.
>> If I decide to evolve code using a tuple type, for instance adding
>> new information and so extend a 4-uple in a 5-uple, then the compiler
>> will tell me all the places that I need to update, which is good.
>> If I use records instead, and have 4 fields, and I want to add again
>> some new information in a new field, then the way the compiler works
>> right now will not help me at all. E.g with this code
>>
>> type record = {
>> field1: int;
>> field2: int;
>> }
>> let foo = function
>> { field1 = v1; field2 = v2 } -> ...
>>
>>
>> If I extend record with a new field field3, then ocaml will
>> not warn me and tell me to modify also the 'foo' function :(
>
> On the other hand that is a verry good thing.
>
I didn't say records have only disadvantages.
> let set_field1 r x = { r with field1 = x }
> let set_field2 r x = { r with field2 = x }
>
> Try doing that with tuples and then add a 3rd, 4th, 5th field.
>
> I have to say I didn't even know you could match a record partially
> or have ever wanted to match a record at all. I use record only when I
> have a collection of otherwise independent values. As such any
> matching will be done on a single component of the record but never
> pairs of them. At least I can't remember having done so before.
Ok ...
Sometimes people want the partial match behavior, but sometimes people
prefer another behavior, so I just propose a kind of annotation
in the pattern that describes what behavior the programmer wants.
>
> MfG
> Goswin
next prev parent reply other threads:[~2009-04-14 16:59 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-14 14:12 Yoann Padioleau
2009-04-14 16:00 ` [Caml-list] " Christophe TROESTLER
2009-04-14 16:40 ` Goswin von Brederlow
2009-04-14 16:58 ` Yoann Padioleau [this message]
2009-04-14 20:01 ` Christophe Raffalli
2009-04-15 0:44 ` Yaron Minsky
2009-04-15 1:46 ` Pal-Kristian Engstad
2009-04-15 2:37 ` Yaron Minsky
2009-04-15 2:40 ` Ashish Agarwal
2009-04-16 16:05 ` Goswin von Brederlow
2009-04-16 16:59 ` David Allsopp
2009-04-17 0:26 ` Jacques Garrigue
2009-04-17 21:12 ` Goswin von Brederlow
2009-04-15 7:41 ` blue storm
2009-04-15 9:30 ` Martin Jambon
2009-04-15 11:01 ` Yaron Minsky
2009-04-15 12:04 ` Martin Jambon
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=87myajuq8d.fsf@aryx.cs.uiuc.edu \
--to=padator@wanadoo.fr \
--cc=caml-list@inria.fr \
--cc=goswin-v-b@web.de \
/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