Doing IO in foldr repeats lines?

Ian Lynagh igloo@earth.li
Sat, 20 Jan 2001 21:17:43 +0000


Hi all

The following code:
                                                
> module Main (main) where                      
                                                
> import IO                                     
                                                
> main :: IO()                                  
> main = do _ <- foldl foo (return 14) ["qq\n", "ww\n", "ee\n"]
>           putStr ""                           
                                                
> foo :: IO Int -> String -> IO Int             
> foo io_l s = do l <- io_l                     
>                 () <- putStr s                
>                 io_l                          

prints (with both GHC and hugs):

qq
ww
qq
ee
qq
ww
qq

and I really don't understand why. Is the code re-evaluated every time
foldl is expanded or something?


Thanks
Ian, confused