[Haskell-beginners] The main thread and waiting for other threads

Thomas Friedrich info at suud.de
Tue May 12 12:27:06 EDT 2009


Hi everyone,

I have a problem with the following example in the Real World Haskell 
book, which aims to develop a module for controlling different threads. See,

http://book.realworldhaskell.org/read/concurrent-and-multicore-programming.html

in the chapter "The main thread and waiting for other threads".

-- file: ch24/NiceFork.hs
import Control.Concurrent
import Control.Exception (Exception, try)
import qualified Data.Map as M

data ThreadStatus = Running
                  | Finished         -- terminated normally
                  | Threw Exception  -- killed by uncaught exception
                    deriving (Eq, Show)

-- | Create a new thread manager.
newManager :: IO ThreadManager

-- | Create a new managed thread.
forkManaged :: ThreadManager -> IO () -> IO ThreadId

-- | Immediately return the status of a managed thread.
getStatus :: ThreadManager -> ThreadId -> IO (Maybe ThreadStatus)

-- | Block until a specific managed thread terminates.
waitFor :: ThreadManager -> ThreadId -> IO (Maybe ThreadStatus)

-- | Block until all managed threads terminate.
waitAll :: ThreadManager -> IO ()

When I run this through ghci I get the following failure:

[1 of 1] Compiling NiceFork         ( NiceFork.hs, interpreted )

NiceFork.hs:17:26:
    Class `Exception' used as a type
    In the type `Exception'
    In the data type declaration for `ThreadStatus'
Failed, modules loaded: none.


Any idea on how to solve this?  Exception is a class not a type, so what 
to put there instead?

Cheers,
Thomas




More information about the Beginners mailing list