Talk:Generic swap

From Rosetta Code
Revision as of 05:08, 14 November 2007 by rosettacode>Mwn3d (New section: C++)

This task description seems to me a little too language-specific in its concepts.

The statement that "The generic routine is created with one or more generic formal parameters" could be read to exclude a Haskell function with an inferred, rather than explicit, type signature, or any language with an implicit universal type ("dynamically typed").

Broadly, the task description seems to me to overspecify a particular means of operation, rather than only "do this sort of thing in a way appropriate to the language".

To demonstrate the problem, I've written Haskell, E, and Perl examples. I'd like to see the intent of the task better described so that these examples are clearly correct or incorrect.

--Kevin Reid 18:13, 7 September 2007 (EDT)

I have adjusted the task definition. Please let me know if you have any more questions.

--Waldorf 18:11, 7 September 2007 (MDT)

Thanks; I think that's much better.

Since you ask, I was also wondering about how broadly to interpret "swap". For example, I wrote two examples which don't exchange values in mutable cells (as the Ada, Perl, and first E example do), but rather accept two values and produce them in the opposite order. (However, the Haskell version could easily be used in an imperatively-expressed program; e.g. modify swap.)

--Kevin Reid 21:41, 7 September 2007 (EDT)

I do not want to limit the implementation. I am after the abstract functionality. I chose "swap" because it is conceptually simple. I am more interested in demonstrating genericity than the low level nature of swap.

--Waldorf 20:27, 7 September 2007 (MDT)

C++

Woudl the C++ example here assume that there is a copy constructor for T types? Would it be better to have "tmp = left" rather than "tmp(left)"? --Usermwn3d:mwn3d 00:08, 14 November 2007