Constructing a tuple (or list) from already-existing objects - what is the cost?

Viewed 558

Suppose we have a function like this one:

foo (x, _, y) = (x, y)

What it does is, it takes a 3-tuple and returns a pair consisting of the first and third elements of the original tuple.

Now suppose we were to pass this function a 3-tuple consisting of some heavyweight objects. Would the two objects be copied to create a new tuple, or does the tuple's internal representation contain only references to objects?

I figure that, since data in Haskell is immutable, no additional copying would be needed, but I just want to be sure.

If this behavior is implementation-defined, I'd like to know what different implementations do in such cases.

2 Answers
Related