List comprehensions (or ZF-expressions) include a sequence of qualifiers, which can be generators or Boolean-valued expressions ("filter expressions") acting as guards.
A list comprehension with no qualifier – for instance, [1 | ]
– is (apparently) valid in Miranda1 (p. 130), but is invalid in Haskell2, 3 (p. 42) –I tried it in the ghci
interpreter– and is (apparently) invalid in Clean4.
(Of course, we could simulate it by adding a True
guard, for instance [1 | True]
. But this is more verbose.)
An example of use of a list comprehension with no qualifier in the literature1 (pp. 134-136) is the following instance of equational reasoning:
[E | ] ++ L = [E] ++ L = (E:[]) ++ L = E:L
Why did Haskell and Clean programming language designers decide against list comprehensions without qualifiers? Is there something that would cause bad feature interactions in these languages but not in Miranda?
References:
Simon L. Peyton Jones. The Implementation of Functional Programming Languages. Prentice Hall. 1987.
The Haskell 98 Report, section 3.11 "List Comprehensions". 1998.
Peter Wentworth. An Introduction to Functional Programming Using Hugs. 2013.
Rinus Plasmeijer; Marko van Eekelen; John van Groningen. Clean Language Report, version 2.2. 2011.