HaskellWiki

Haskell | Wiki community | Recent changes
Random page | Special pages

 

Not logged in
Log in | Help

Singleton list confusion

Categories: Syntax

Why do Haskell newcomers frequently believe, that list variables must be enclosed in brackets? People sometimes write argument patterns like [x], hoping that x will assume all values of a list successively. Example:

case xs of
   [x] -> [f x]

although they meant

[f x | x <- xs]

or just map f xs. It seems like they expect some kind of list comprehension. However, if there wouldn't be a special list notation and if there wouldn't be the special syntax for the list type constructor (thus we must write [a] instead of List a), then there would be certainly less confusion.

See for example Haskell-Cafe about testing for same characters in lists of strings, Pattern match failure

Retrieved from "http://www.haskell.org/haskellwiki/Singleton_list_confusion"

This page has been accessed 403 times. This page was last modified 07:16, 11 April 2008. Recent content is available under a simple permissive license.