[Haskell-beginners] Forcing output of show
Daniel Fischer
daniel.is.fischer at googlemail.com
Wed Oct 26 16:29:52 CEST 2011
On Wednesday 26 October 2011, 16:23:20, Hugo Ferreira wrote:
> Hello,
>
> Apologies for this newbie question.
> I have a test function:
>
> testLearnRules train = do
> h <- IO.openFile train IO.ReadMode
> c <- IO.hGetContents h
> let proposedRules = instRules $ words c
> let rs = take 10 $ M.assocs proposedRules
> let _ = show rs
> -- let _ = length rs
> return ()
>
> I realize that nothing is executed due to Haskell's
> lazy evaluation. How can I force show to print
> something to the screen?
You can't force show to rpint something, since show is a pure function not
involving IO.
However, testLearnRules does involve IO, so instead of
let _ = show rs
you could simply print it out,
print rs
-- equivalently, putStrLn (show rs)
>
> Appreciate any pointers,
>
> TIA,
> Hugo F.
More information about the Beginners
mailing list