Reputation: 631
When running IO
actions in GHCi prompt it automatically runs the action and shows result, this is nice, but not for students trying to understand difference between IO
and non-IO
. Is there a way to change configuration of GHCi so that it runs the action, but shows something like <<IO Int action>>
instead? Something more like result for ST actions (but action should be performed):
now it does:
> return 1 :: IO Int
1
> return 1 :: ST s Int
<<ST action>>
i would like:
> return 1 :: IO Int
<<IO Int action>>
> putStrLn "bla"
bla
<<IO () action>>
Edit:
IO
is probably the only thing handled specially by GHCi, ST
actually has instance for Show (ST s a)
which returns "<<ST action>>"
. So maybe if I could disable this special treatment of IO
it would be sufficient.IO
type, but then interpreter will not run the action). If GHCi could automatically wrap IO
actions somehow, that would be an option.Upvotes: 18
Views: 1237
Reputation: 62818
This is an interesting question. The only thing I can come up with is writing some kind of custom prelude module that exports a type called IO
, but which isn't "the" I/O type that GHCi is special-casing.
Of course, this is no help at all unless the student remembers to import this rather than the real prelude. I suppose you could write that into the GHCi config file, but... well, it's certainly not perfect.
The only other way I can think of is to use the GHC-API to basically reimplement GHCi yourself. But that sounds like waaaay too much work...
Upvotes: 2