unsafePerformIO to give warnings
Simon Marlow
simonmar@microsoft.com
Fri, 21 Dec 2001 12:29:05 -0000
Ian Lynagh writes:
> Sorry, I meant "hugs and ghci only seem to print the warning the first
> time I run the program", e.g. with
>=20
> module Main where
>=20
> import IOExts
>=20
> main :: IO()
> main =3D trace "foo" (putStrLn "bar")
>=20
> in hugs:
>=20
> [...]
> Type :? for help
> Main> main
> foobar
>=20
> Main> main
> bar
[snip]
> and in ghci:
>=20
> Skipping Main ( q.lhs, ./q.o )
> Main> main
> foo
> bar
> Main> main
> bar
[snip]
This is because 'main' is a CAF: the act of reducing it to normal form
the first time forces the warning to be printed, but thereafter the
evaluated version is returned immediately.
To subvert this behaviour, in GHCi you can say ':set +r' which causes
all CAFs to be reverted between evaluations.
Cheers,
Simon