fork download
  1. import Control.Monad
  2.  
  3. for :: [a] -> (a -> b) -> [b]
  4. for = flip map
  5.  
  6. cube :: Integer -> Integer -> Integer -> [[[Integer]]]
  7. cube x y z = for [0..x-1] $ \i -> for [0..y-1] $ \j -> for [0..z-1] $ \k -> z*y*i + z*j + k
  8.  
  9. main :: IO ()
  10. main = printCube $ cube 2 3 4
  11. where printCube = mapM_ ((const $ putStrLn "") <=< mapM_ print)
  12.  
Success #stdin #stdout 0s 6228KB
stdin
Standard input is empty
stdout
[0,1,2,3]
[4,5,6,7]
[8,9,10,11]

[12,13,14,15]
[16,17,18,19]
[20,21,22,23]