Translation of nested for loops into Haskell -


i struggling translate piece of matrix multiplication in f# haskell (pls forget parallel component):

parallel.for(0, rowsa, (fun i->         j = 0 colsb - 1            k = 0 colsa - 1               result.[i,j] <- result.[i,j] + a.[i,k] * b.[k,j]))       |> ignore 

all managed put

sum (map (\(i, j, k) -> (my.read (a,i,k)) * (my.read (b, k, j))) [ (i, j, k) | <- [0..rowsa], j <- [0..colsb], k <- [0..colsa] ])   --my.read reads values of respective cells 'my' database 

the intention read cells of matrix , matrix b database , matrix multiplication can carried out in portions different agents. controlled setting boundaries , j , k not relevant here.

i have tried translate above f# sample haskell. issue struggling result not sum on there should list of results @ position i, j(f# result.[i,j] - cell result matrix). not see how emit right result (i,j). maybe must further take apart?

what original code doing? also, type signature of my.read? assume have signature similar num b => (a, int, int) -> io b, in case code not compile. if my . read in io monad, write as:

myfunc =     let indices = [(i, j, k) | <- [0..rowsa],                                j <- [0..colsb],                                k <- [0..colsa]]      -- since `my . read` returns value in io monad,     -- can't multiply values returned.     r1 <- mapm (\(i, j, k) -> (my . read) (a, i, k)) indices     r2 <- mapm (\(i, j, k) -> (my . read) (b, k, j)) indices      -- can multiply r1 , r2 though,     -- since values extracted io monad     return $ sum $ zipwith (*) r1 r2 

the best advice can give right use ghci figure out types.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -