Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Haskell
Wiki community
Recent changes
Random page
HaskellWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Syntactic sugar/Cons
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== Comma separated list elements ==== We are used to the [[list notation]] <hask>[0,1,2,3]</hask>. I think many Haskell users are not aware that it is a special notation. They don't know that it is a replacement for <hask>(0:1:2:3:[])</hask>, and because of that they also can't derive that a function for constructing single element list can be written as <hask>(:[])</hask>. The comma separated list notation <hask>[0,1,2,3]</hask> is very common, but is it sensible? There are two reasons against: * The theoretical reason: The intuitive list notation using comma separation requires one comma less than the number of elements, an empty list would need -1 commas, which can't be written, obviously. * The practical reason: The colon is like a terminator. Each list element is followed by the colon, 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. Although the list type has so many special support by the Haskell 98 language, there is no need for some syntactic support. The definition data List a = End | (:) a (List a) is regular Haskell98 code. The colon should have precedence below <hask>($)</hask>. Then a list type can be <hask>List Int</hask> and a list value can be <hask>1 : 2 : 3 : End</hask>. Again, this proves the power of the basic features of Haskell98.
Summary:
Please note that all contributions to HaskellWiki are considered to be released under simple permissive license (see
HaskellWiki:Copyrights
for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel
Editing help
(opens in new window)
Toggle limited content width