Is there something deeper to it, or is it just a shitty excuse for not writing, e.g. three for loops in [(a, b, c) | a <- [1..10], b <- [1..10], c <- [1..10], a^2 + b^2 == c^2] and it still being O(n3)?
It's a nice syntax.
You can compile it into C and see that it folds into three loops.
Name:
Anonymous2009-05-11 1:06
That's what I expected, haskell can't even optimize loops *grabs dick*
Name:
Anonymous2009-05-11 1:33
>>1 For Loops
Is there something deeper to it, or is it just a shitty way to write e.g. [(a, b, c) | a <- [1..10], b <- [1..10], c <- [1..10], a^2 + b^2 == c^2]?
Also I don't think you know how big O notation works.
Name:
Anonymous2009-05-11 1:58
>>4 Also I don't think you know how big O notation works.
You're clueless.
Hand-crafted pointless style is superior. Please, do suggest improvements. (Maybe some parens can be removed... I don't have a compiler handy to test, though.)
Name:
Anonymous2009-05-12 12:24
This is based on >>20's version: catMaybes . (join.join) (liftM3 ((liftA2.liftA2.liftA2) (>>) ((((. (^2)) . (guard .)) .) . ((==) .) . ((+) `on` (^2))) (((return .) .) . (,,)))) . enumFromTo 1
pl'ing the actual guard (\a b c -> guard (a^2 + b^2 == c^2)) turns out to be inelegant. This a bit better: catMaybes . (join.join) (liftM3 ((liftA2.liftA2.liftA2) (>>) (\a b c -> guard (a^2 + b^2 == c^2)) (((return .) .) . (,,)))) . enumFromTo 1