Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] Feature request : Tuples vs. records
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Brian Hurt <bhurt@s...>
Subject: Re: [Caml-list] Feature request : Tuples vs. records


On Sat, 24 Feb 2007, Lukasz Stafiniak wrote:

> I have this idea... We could have row polymorphism in tuples, without
> any impact on performance! Instead of insisting that ('a * 'b) means
> exactly two elements, we could have (> 'a * 'b) at least two elements.
> Any projections or pattern matching fetches the tuple fields without
> problems: it doesn't need to care that there are more than it needs.
>
> Say you realize that you need to return another value from a function
> (which already returns a tuple): you would only modify the function
> and not its uses.

Not being able to do this is one of the reasons I *like* Ocaml.

Consider the case where the calling location is:
 	let a, b = foo ... in
 	...

Now you change foo to return 3 tuples instead of just 2.  What happens?

If you say "The third element quietly gets dropped", I'll respond with "if 
I wanted that behavior, I'd be coding in Perl."

If you've changed what you're returning, you've change the semantics of 
the function- what it means is now different.  And it's a good idea to go 
look at every place where it's called, and consider what effect this 
change in semantics will have on that code.  Ocaml is very helpfull in 
that it will tell you every place you need to look at to deal with this 
change- filename and line number.  Note that if you, the programmer, 
decide that the right thing to do is to just drop the new third argument, 
it's real easy ro change the calling code to just:
 	let a, b, _ = foo ... in
 	...


Brian