[Haskell-beginners] Why does this list comprehension return an empty list?

Kim-Ee Yeoh ky3 at atamo.com
Wed Jul 24 03:07:00 CEST 2013


On Tue, Jul 23, 2013 at 3:53 PM, Costello, Roger L. <costello at mitre.org>wrote:

> I have a list comprehension that extracts the singletons from xs using f
> and g, and creates a pair from their output:
>
>         [(a,b) | a <- f xs, b <- g xs]
>
> I executed this and the result is the empty list:
>
>         []
>
> That is odd. Why is the empty list the result?
>

For the same reason that the cartesian product of any set with the empty
set is the empty set.

Also,

> I have a list of singletons:
>        xs = [("a")]

is immediately suspect, since you have xs:: [String], whereas "a list of
singletons" appears to lean quite a lot more toward [Char], which is just
String.

-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130724/3cd35bb2/attachment.htm>


More information about the Beginners mailing list