The main thread and waiting for other threads

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.h... 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

Am Dienstag 12 Mai 2009 18:27:06 schrieb Thomas Friedrich:
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". 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.
The book was written in the times of GHC 6.8.*, when Exception was a type. In GHC 6.10, it became a class because it was considered a bad idea to catch general exceptions, one should use adequate handlers for specific exceptions instead. Of course, that broke some code out there.
Any idea on how to solve this? Exception is a class not a type, so what to put there instead?
For those who want to catch general exceptions, there is data SomeException = forall e . Exception e => SomeException e in Control.Exception, which should be roughly equivalent to the old Exception type. So replace Exception with SomeException in ThreadStatus, perhaps insert a few calls to toException in the appropriate places (the compiler will help you find them) and it should work.
Cheers, Thomas
Cheers, Daniel

The problem is that Exception is a class. You should use SomeException,
which is a type!
On Tue, May 12, 2009 at 13:27, Thomas Friedrich
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.h...
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
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- Rafael Gustavo da Cunha Pereira Pinto Electronic Engineer, MSc.

As Daniel Fischer already wrote, this is due to an API change in GHC
6.10. But the old exceptions interface is still available as
Control.OldException; you can simply import that instead of
Control.Exception.
On Tue, 12 May 2009 12:27:06 -0400
Thomas Friedrich
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.h...
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
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (4)
-
Daniel Fischer
-
Quentin Moser
-
Rafael Gustavo da Cunha Pereira Pinto
-
Thomas Friedrich