[Haskell-cafe] Re Is the Haskell list comprehension just a Cartesian product machine?

Douglas McIlroy douglas.mcilroy at dartmouth.edu
Wed Dec 8 15:29:35 UTC 2021


> could I explain Haskell list comprehensions as basically just a
> Cartesian/cross product machine?

Another deviation from the simple explanation: the pair (2,1) never
appears in an enumeration from the Haskell expression
         [(x,y)  | x<-[1..], y<-[1..]]
Although the notation is adapted from set theory, it does not
necessarily reflect the meaning of its set-theory analog. A list
comprehension specifies an enumeration order. In the present case that
ordering is not well founded: some elements have an infinite
descending chain of predecessors and thus never appear in the
enumeration.

Doug


More information about the Haskell-Cafe mailing list