[tor-dev] PRELIMINARY: [PATCH 3/3] Add the 'FlexibleInstances' extension.

Nikita Karetnikov nikita at karetnikov.org
Sat Aug 3 19:40:58 UTC 2013


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-extensions.html#instance-rules
[3] https://lists.torproject.org/pipermail/tor-dev/2013-July/005157.html

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Replace-TorDNSEL.Compat.Exception-with-Control.Excep.patch
Type: text/x-diff
Size: 10754 bytes
Desc: not available
URL: <http://lists.torproject.org/pipermail/tor-dev/attachments/20130803/5f0a02e2/attachment.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Import-the-CInt-constructor-properly.patch
Type: text/x-diff
Size: 898 bytes
Desc: not available
URL: <http://lists.torproject.org/pipermail/tor-dev/attachments/20130803/5f0a02e2/attachment-0001.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-Add-the-FlexibleInstances-extension.patch
Type: text/x-diff
Size: 812 bytes
Desc: not available
URL: <http://lists.torproject.org/pipermail/tor-dev/attachments/20130803/5f0a02e2/attachment-0002.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.torproject.org/pipermail/tor-dev/attachments/20130803/5f0a02e2/attachment.sig>


More information about the tor-dev mailing list