Jakub
Jakub

Reputation: 21

Haskell Data constructor not in scope

I've been researching it and wanted to try out some code with MVar. I'm checking this code through an online compiler.

Below is the code I'm trying to test:

main = do
  m <- newEmptyMVar
  forkIO $ putMVar m 'X'
  r <- takeMVar m
  print r

And below here are the errors I'm getting:

main.hs:2:8: error: Variable not in scope: newEmptyMVar :: IO t1

main.hs:3:3: error:
    Data constructor not in scope: IO :: t0 -> IO a0

main.hs:3:8: error:
    • Variable not in scope: putMVar :: t1 -> Char -> t0
    • Perhaps you meant ‘putChar’ (imported from Prelude)

main.hs:4:8: error: Variable not in scope: takeMVar :: t1 -> IO a1

Upvotes: 0

Views: 219

Answers (1)

Daniel Wagner
Daniel Wagner

Reputation: 153352

You must import a module that exports these functions; in this case, Control.Concurrent would be a good choice. If you didn't already know which module was needed, one way to find out is to use Hoogle.

Upvotes: 2

Related Questions