
The major reason to use list comprehensions in Haskell is when things resemble cartesian products.

These two lists are then recursively sorted. It generates two lists, one of elements greater than or equal to the 'pivot' element (in this case the first element of the list), and one of elements less than the pivot.

Ghci > factorial :: Int -> Int factorial n = product ghci > factorial 10 - okay, this is fine 3628800 ghci > factorial 100 - (silent) overflow! 0 ghci > factorial :: Integer -> Integer factorial n = product ghci > factorial 100 - woo! works great! 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000 ghci > factorial 10000 - also works fine! so many digits. Haskell has list comprehensions, which are a lot like set comprehensions in math and similar implementations in imperative languages such as Python and. In Haskell, I find that map and filter are syntactically much nicer than in Python, especially with point-free style theyre also more natural for me to think about, so as a rule of thumb, Id say, 'Prefer map and filter to list comprehensions when possible.'. The classic presentation of quicksort in Haskell is a direct implementation using list comprehensions.
