Determining if a set of 2d vectors is a valid function My idea was to take in the function and perform a self cross product so that I could check every pair against every other pair. I'm new to Haskell so this solution is probably rough.

My question is, is there a better way to emulate a nested for loop rather than a cross product? Also, is there any way to collapse my ugly valid and valid' into one clean function?

valid :: [(Int, Int)] -&gt; Bool
valid f = valid' $ [(x,y) | x &lt;- f, y &lt;- f]

valid' :: [((Int,Int),(Int,Int))] -&gt; Bool
valid' [] = True
valid' (((x,y),(x1,y1)):xs) = valid' xs &amp;&amp; if x == x1 then (if y == y1 then True else False) else True
To start, if y == y1 then True else False can be simplified to y == y1:

valid' (((x,y),(x1,y1)):xs) = valid' xs &amp;&amp; if x == x1 then y == y1 else True