[Haskell-cafe] Haskell vs OCaml

Tomasz Zielonka tomasz.zielonka at gmail.com
Sun Dec 25 06:16:29 EST 2005


On Sun, Dec 25, 2005 at 11:09:51AM +0000, Branimir Maksimovic wrote:
> >Or just 'mapM_ doSomething [1..10]' (:
> 
> Neet! However would it be more efficient for, say, 1 million iterations?
> Anyway I have to look for map functions. I'm learning step by step
> from tutorials :)

I remember I was impressed when I checked what GHC made of such code.
No lists, no allocations, just a tight loop :-)

BTW, in my library of small Haskell utilities I have

    for_ l f = mapM_ f l
    for l f = mapM f l

and I use it like this

    for_ [1..10] $ \i -> do
        do something with i

It's just because there's often more code in f than in l.

When I don't have my handy little library, I use a more baroque syntax:

    (`mapM_` [1..10]) $ \i -> do
        do something with i

Now that I think about it, this variant would be nicer:

    flip mapM_ [1..10] $ \i -> do
        do something with i

Best regards
Tomasz

-- 
I am searching for a programmer who is good at least in some of
[Haskell, ML, C++, Linux, FreeBSD, math] for work in Warsaw, Poland


More information about the Haskell-Cafe mailing list