This is a follow up question to this. I'm using a graphic library in Haskell called Threepenny-GUI. In this library the main function returns a UI
monad object. I'm trying to execute a simple print command with no success. What is a right work around to enable printing for debugging purposes.
Code:
main :: IO ()
main = startGUI defaultConfig setup
setup :: Window -> UI ()
setup w = do
print "debug message 1 "
Error:
Couldn't match type ‘IO’ with ‘UI’
Expected type: UI ()
Actual type: IO ()
In a stmt of a 'do' block: print "labels and values "
Based on the types, this is a good application of
liftIO
.liftIO
has a typeMonadIO m => IO a -> m a
so it can be used like this:The type of that expression can be
UI ()
sinceUI
is an instance ofMonadIO
andprint "debug message 1"
has the typeIO ()
.