putStr
Hal Daume III
hdaume at ISI.EDU
Mon Oct 13 10:56:07 EDT 2003
In general, you can't, not with these type signatures, since printing
something is a side effect.
If this is only for debugging purposes, you might try using trace from
IOExts. You can use it in a nice fashion like:
> f1 :: Int -> Int
> f1 x
> | trace ("The initial value is " ++ show x) False = undefined
> | otherwise = f2 x
In general, the 'trace ... False = undefined' thing is quite useful, but
note that trace uses unsafePerformIO and very little is guarenteed about
the output (especially the ordering might be different than you would
expect...but it's usually fine for debugging purposes).
On 13 Oct 2003, 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.
>
> How could I do this?
>
>
> Thank you
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
--
Hal Daume III | hdaume at isi.edu
"Arrest this man, he talks in maths." | www.isi.edu/~hdaume
More information about the Haskell-Cafe
mailing list