putStr

Shawn P. Garbett listman at garbett.org
Mon Oct 13 13:06:16 EDT 2003


On Monday 13 October 2003 11:54 am, Jose Morais wrote:
> Hi,
>
> 	I am trying to something like
>
> f1 :: Int -> Int
> f1 x = f2 x
>
> f2 :: Int -> Int
> f2 x = 2 * x
>
>
> 	but before f2 returns its result I'd like it to print something like
> "The initial value is " ++ show x.
>

f1 :: Int -> IO Int
f1 x = f2 x

f2 :: Int -> IO Int
f2 x = do
            putStrLn $ "The initial value is " ++ show x
            return (2 * x)

The previously mentioned trace method is prefered for debugging because 
with this, one is now in the IO monad.

Shawn


More information about the Haskell-Cafe mailing list