Haskell UI do clause, how to print?

451 views Asked by At

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 "
1

There are 1 answers

4
David Young On BEST ANSWER

Based on the types, this is a good application of liftIO. liftIO has a type MonadIO m => IO a -> m a so it can be used like this:

liftIO (print "debug message 1")

The type of that expression can be UI () since UI is an instance of MonadIO and print "debug message 1" has the type IO ().