Skip to content

Another mistake in ch5 #2

@ajkavanagh

Description

@ajkavanagh

The nested comprehension isn't correct:

*Main> [(x,y) | x <- [1,2], y <- [3,4]]
[(1,3),(1,4),(2,3),(2,4)]

nestedComprehension xs ys = concat [[(x, y) | x <- xs] | y <- ys]

*Main> nestedComprehension [1,2] [3,4]
[(1,3),(2,3),(1,4),(2,4)]

is sadly wrong. The x <- xs and y <- ys need to be switched:

nestedComprehension xs ys = concat [[(x, y) | y <- ys] | x <- xs]

*Main> nestedComprehension [1,2] [3,4]
[(1,3),(1,4),(2,3),(2,4)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions