[Haskell-cafe] Great language shootout: reloaded

Bulat Ziganshin bulat.ziganshin at gmail.com
Sat Nov 11 04:00:49 EST 2006

Hello Isaac,

Saturday, November 11, 2006, 5:56:57 AM, you wrote:

> 2) Some Haskell programs were pushed into 'interesting alternative
> implementations' because they'd strayed so far from the spirit of the
> benchmark. (It takes a while for people to notice and complain, but
> eventually they do.)

it's very real :)  while ghc allows to write rather fast programs, such
programs are much harder to write and manage than even equivalent C
ones! just for comparison:

-- compact, but very slow
s = sum arr

// not so compact, but very fast
double sum=0; for(int i=0; i<10; i++)  sum+=arr[i];

// nor fast, nor compact, nor in Haskell spirit anyway :))
sum' <- newIORef 0
for 0 10 $ \i ->
  do  x <- unsafeRead arr i
      sum <- readIORef sum'
      writeIORef sum' (sum+x)
for :: Int -> Int -> (Int -> IO a) -> IO ()
-- Faster equivalent of "mapM_ action [from..to-1]"
for from to action  = go from
    go i | i>=to      = return ()
         | otherwise = do action i
                          go $! (i+1)

Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com

More information about the Haskell-Cafe mailing list