{-
main = do putStrLn (show (stupid_mul 100))
putStrLn "100 multiplications done"
stupid_mul 0 = []
stupid_mul it = (s_mul it) : stupid_mul (it-1) -- without "it" after s_mul only one multiplication is executed
s_mul it = mul (replicate 4000 [0..3999]) (replicate 4000 2)
mul :: [[Double]] -> [Double] -> [Double]
mul [] _ = []
mul (b:bs) c | sp==0 = sp : (mul bs c) -- always false, force evaluation
| otherwise = (mul bs c)
where sp = (scalar b c)
scalar :: [Double] -> [Double] -> Double
scalar _ [] = 0
scalar [] _ = 0
scalar (v:vs) (w:ws) = (v*w) + (scalar vs ws)
-}
import Data.Array.Vector
n :: Int
n = 4000
main = print (sumU (zipWithU (*) a b))
where
a = replicateU n (2::Double)
b = mapU (realToFrac::Int->Double) $ enumFromToU 0 (n-1)