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
The list to tuple problem could be handled with Template Haskell like this (running
ghci -XTemplateHaskell
):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)
You could use something like this:
This will give you a list of point lists, you can assume that all these sublists have the same length. It should work like this: