Haskell/Solutions/Lists III

Scans
In the efficient  implementations above, we use   and   as a way to avoid having to break down the list argument with pattern matching in the where clause only to assemble it back in the right-hand side. In the Pattern matching chapter, we will see how as-patterns allow us to reach the same effect without needing.

filter and list comprehension
The boolean conditions in a list comprehension are evaluated in order, so if you swapped the conditions like this: If one of the l turned out to be an empty list the program would try to apply head on it, which would cause an error. Putting not (null l) first causes the program to, when it meets an empty list, to short-circuit the conditional - that is, ignore the second condition since the first one being false is enough for rejecting the list - thus avoiding doing head [] and the error that follows. Alternatively you may filter by pattern matching. Only non-empty lists match divided by the first element  followed by the possibly empty tail  :