Monday, 6 June 2016

Haskell: Get the cross product of two lists

Prelude> let crossProduct list1 list2 = [(x, y) | x <- list1,  y <- list2]
Prelude> 
Prelude> crossProduct [1, 2, 3] [4, 5, 6]
[(1,4),(1,5),(1,6),(2,4),(2,5),(2,6),(3,4),(3,5),(3,6)]

Previous                                                 Next                                                 Home

No comments:

Post a Comment