[Haskell-cafe] for loops and 2d arrays in haskell

Sebastian Sylvan sebastian.sylvan at gmail.com
Fri Jan 19 02:54:35 EST 2007


On 1/19/07, Fernan Bolando <fernanbolando at mailc.net> 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 ]

--
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862


More information about the Haskell-Cafe mailing list