[Haskell-cafe] Slow IO or bad code?
Lutz Donnerhacke
lutz at iks-jena.de
Thu Aug 9 08:38:22 EDT 2007
* Vimal wrote:
>>> Beginning of CODE
> loop t function
> | t == 1 = do function
> | otherwise = do { function; loop (t - 1) function }
>
> prod [] [] = 0
> prod (a:as) (b:bs) = a*b + prod as bs
prod = sum . zipWith (*)
> to_int :: [String] -> [Integer]
> to_int [] = []
> to_int (x:xs) = (read x) : to_int xs
This is the slow part. Prelude.read ist really slow.
Futhermore use the recusion pattern again:
to_int = map read
> doit = do
> n <- getLine
> a <- getLine
> b <- getLine
> let la = to_int (words a);
> lb = to_int (words b); in
> print (prod la lb)
What is n used for?
More information about the Haskell-Cafe
mailing list