How can I print the type (Either String (IO String))?
The solution is one liner ....
either print (print =<<)
If you want to differentiate whether it was Left
or Right
is a little more important, see @jamsihdh's answer.
Note that this cannot be done by an instance Show
, as nothing can be purely observable about the values โโof the type IO a
.
source to share
The solution is not one liner ....
The monad is IO
not an instance Show
, so you cannot just use print
. In fact, the value in the IO monad must be received first.
You can view the value x::Either String (IO String)
by placing it in your body.
case x of
Left s -> putStrLn ("Left " ++ show s)
Right getVal -> do
s <- getVal
putStrLn ("Right (IO " ++ show s ++ ")")
and it has to resolve and print the value.
Edit -
I was misunderstood by @luqui, :) which is great because I learned a thing or two ....
Of course, now I have to go one step further and expose one liner with the corresponding left and right notation. :)
either (print . ("Left " ++)) ((print =<<) . fmap ("Right IO " ++))
source to share