* The theoretical reason: In separator notations there is one comma less than the number of elements. An empty list would need -1 commas, which can't be written, obviously. That is, empty lists must always be handled differently in the separator approach. There is no such problem with terminators.

* The theoretical reason: In separator notations there is one comma less than the number of elements. An empty list would need -1 commas, which can't be written, obviously. That is, empty lists must always be handled differently in the separator approach. There is no such problem with terminators.

−

* The practical reason: In terminator notation, each list element is followed by the terminator symbol. Thus it is easier to reorder the elements of a list in an editor. If you have written <hask>(1:2:3:[])</hask> you can simply cut some elements and the subsequent ':' and then you can insert them whereever you want.

+

* The practical reason: In terminator notation, each list element is followed by the terminator symbol. Thus it is easier to reorder the elements of a list in an editor. If you have written <hask>(1:2:3:[])</hask> you can simply cut some elements and the subsequent ':' and then you can insert them whereever you want. For similar reasons terminator notation is easier to handle for [[Darcs|VCS]] and diff.

[[Category:Syntax]]

[[Category:Syntax]]

Revision as of 18:07, 12 June 2009

There are several concepts for notation of sequences of elements.
Usually, we don't think much about it.
Programming languages provide different schemes,
often different schemes in the same language,
we are used to them, and no scheme seems to be better than the other one.
However, there are differences and good reasons for preferences.

1 Terms

Separator: There is a symbol between each element. This is what the functions

Data.List.intersperse

and

Data.List.unwords

generate. In Haskell language, the following syntaxes allow separators only:

Initiator? Theoretically it would also be possible to introduce each list element with some symbol. However, I don't know if this is used somewhere.

2 Terminators are better

The theoretical reason: In separator notations there is one comma less than the number of elements. An empty list would need -1 commas, which can't be written, obviously. That is, empty lists must always be handled differently in the separator approach. There is no such problem with terminators.

The practical reason: In terminator notation, each list element is followed by the terminator symbol. Thus it is easier to reorder the elements of a list in an editor. If you have written

(1:2:3:[])

you can simply cut some elements and the subsequent ':' and then you can insert them whereever you want. For similar reasons terminator notation is easier to handle for VCS and diff.