Skip to content

Instantly share code, notes, and snippets.

@gyk
Created September 8, 2014 06:16
Show Gist options
  • Save gyk/fdc7c72c10c0bb478f56 to your computer and use it in GitHub Desktop.
Save gyk/fdc7c72c10c0bb478f56 to your computer and use it in GitHub Desktop.
Test nested do blocks in Haskell
xRange = [2, 3]
yRange = [4..6]
lComprehension = [[(x, y) | y <- yRange] | x <- xRange]
lOperator = xRange >>= (\x -> [yRange >>= \y -> [(x, y)]])
lNestedDo = do
x <- xRange
return $ do
y <- yRange
return (x, y)
main = do
putStrLn $ show lComprehension
putStrLn $ show lOperator
putStrLn $ show lNestedDo
{--
Results:
Three lines of [[(2,4),(2,5),(2,6)],[(3,4),(3,5),(3,6)]]
--}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment