Jn Fairbairn wrote:
> > It's a good idea to use two different types in an example, but Char
> > is not well chosen, because the canonical way to write the above
> > result is ("abc",[1,2,3]).
>
> Good point. String is best:
>
> unzip [("a", 1), ("b", 2), ("c", 3)] = (["a", "b", "c"], [1, 2, 3])
I remember the days when I was a newbie - generally speaking not
necessarily Haskell; anything related to documentation in computer
science - all the given examples would have suggested to me that there
was a required ordering between successive elements of the input list
and/or possibly also a relation between the two components of each
duple ...
unzip [("b", 9), ("m", 2), ("d", 3)] = (["b", "m", "d"], [9, 2, 3])
is better in that respect, but it takes longer to see what happens in
case one isn't distracted. The ideal example doesn't exist.
Another way to specify unzip by example is:
for all X,Y,Z of the same type T1 and A,B,C of the same type T2
unzip [(X, A), (Y, B), (Z, C)] = ([X, Y, Z], [A, B, C])
and maybe the quantification is unnecessary since [X, Y, Z] already
implies X,Y and Z need to be of the same type; and it doesn't suggest
any other constraints - except perhaps that unzip only works for lists
of lenght 3 ...
Specification or documentation by example is extremely difficult,
especially if done for newbies by experts.
Bart Demoen