I’m attaching three patches. For an explanation regarding the ‘FlexibleInstances’ extension see [1,2].
As always, I’ve only fixed critical things. Deprecation warnings can wait.
Perhaps, I’ll combine all similar patches (like those that deal with exceptions) later.
I’ve noticed that the author decided to use ‘Dynamic’-related functions to raise many (all?) exceptions. If you raise an exception of type ‘Dynamic’, you won’t get a meaningful message. Consider the following:
{-# LANGUAGE DeriveDataTypeable #-}
import qualified Control.Exception as E import Data.Dynamic (toDyn) import Data.Typeable (Typeable)
-- | An exception related to links or monitors. data LinkException = NonexistentThread -- ^ deriving (Eq, Typeable)
instance Show LinkException where show NonexistentThread = "Attempt to link to nonexistent thread"
test1 = E.throw . toDyn $ NonexistentThread
instance E.Exception LinkException where
test2 = E.throw NonexistentThread
In GHCi:
*Main> test1 *** Exception: <<LinkException>> *Main> test2 *** Exception: Attempt to link to nonexistent thread
Note that the first argument of ‘E.throw’ must be an instance of ‘E.Exception’:
E.throw :: E.Exception e => e -> a
‘LinkException’ is not an instance of ‘E.Exception’ in ‘TorDNSEL.Control.Concurrent.Link.Internals’. It should be easy to change that.
Later, I’d also like to inspect ‘withLinksDo’, ‘linkTogether’, and replace ‘$’ with ‘.’ in a couple of places.
The previous set of patches is here [3].
[1] http://www.haskell.org/haskellwiki/List_instance [2] http://www.haskell.org/ghc/docs/6.8-latest/html/users_guide/type-class-exten... [3] https://lists.torproject.org/pipermail/tor-dev/2013-July/005157.html