
On 1/19/07, Sebastian Sylvan
On 1/19/07, Sebastian Sylvan
wrote: On 1/19/07, Fernan Bolando
wrote: hi all
Since I am very new to haskell and still learning, I hope I will not annoy poeple by asking the following question.
what is the simplest way to implement the following code in haskell? it's just printing the contents of 2D array.
for(i = 0; i < imax; i++){ for(n = 0; n < nmax; n++){ printf("%i:%i = %f\n", array[i][n]); } }
Do you mean:
for(i = 0; i < imax; i++){ for(n = 0; n < nmax; n++){ printf("%i:%i = %f\n", i,n,array[i][n]); } }
If so, how about:
sequence [ putStr (show i ++ ":" ++ show n ++ " = " show arr!(i,n) | (i,n) <- indices arr ]
Sorry: sequence [ putStrLn (show i ++ ":" ++ show n ++ " = " show arr!(i,n)) | (i,n) <- indices arr ]
Bah, it's way to early, forgot another parenthesis: sequence [ putStrLn (show i ++ ":" ++ show n ++ " = " show (arr!(i,n)) ) | (i,n) <- indices arr ] -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862