Let’s say I want to know all the points on a (x, y) plane that are in the rectangle has.
I can calculate that using List Comprehensions, this way:
let myFun2D = [(x, y) | x <- [0..2], y <- [0..2]]
Now, if I want to accomplish the same for a (x, y, z) space, I can go the same way and do:
let myFun3D = [(x, y, z) | x <- [0..2], y <- [0..2], z <- [0..2]]
Is there a way to generalize this for any number of dimensions? If yes, how?
let myFunGeneralized = ?
Thanks
Unfortunately, because
[(a,a)]and[(a,a,a)]etc are of different types, you can’t write one function to represent all of them.Anyway, in general you could use
If you want an
[[a]]instead, there is a very simple function for this:or (thanks sdcvvc)