[Haskell-cafe] Tail-call optimization

Joel Reymont joelr1 at gmail.com
Sat Dec 10 15:41:52 EST 2005


I always wandered, does ghc do tail-call optimization?

Would it optimize the two variants of the function below or just the  
first one?

--- Proper?

writeLoop :: (Event a -> IO ()) -> Handle -> (SSL, BIO, BIO) -> IO ()
writeLoop post h ssl =
     do handle (\e -> post $ NetworkError e) $
               do cmd <- read h ssl
                  post $! Cmd $! cmd
        writeLoop post h ssl

--- Bad?

writeLoop :: (Event a -> IO ()) -> Handle -> (SSL, BIO, BIO) -> IO ()
writeLoop post h ssl =
     do handle (\e -> post $ NetworkError e) $
               do cmd <- read h ssl
                  post $! Cmd $! cmd
                  writeLoop post h ssl

	Thanks, Joel

--
http://wagerlabs.com/







More information about the Haskell-Cafe mailing list