git.iko.soy/distributed-process
on master help sign in
Small improvement to Traced
706ba61Edsko de Vries
network-transport-2/tests/Traced.hs+7−7
@@ -19,7 +19,7 @@
19-- outputs
19-- outputs
20--
20--
21-- > Hello world
21-- > Hello world
22−-- > *** Exception: user error (Pattern match failure in do expression at tests/Traced.hs:107:3-9)
22+-- > *** Exception: user error (Pattern match failure in do expression at Traced.hs:187:3-9)
23-- > Trace:
23-- > Trace:
24-- > 0 Left 2
24-- > 0 Left 2
25-- > 1 Left 1
25-- > 1 Left 1
@@ -36,11 +36,10 @@
36--
36--
37-- The advantage of this idiom is that it gives you line number information when the guard fails:
37-- The advantage of this idiom is that it gives you line number information when the guard fails:
38--
38--
39−-- > *Traced> test3
39+-- > *Traced> test2
40−-- > *** Exception: user error (Pattern match failure in do expression at tests/Traced.hs:103:3-6)
40+-- > *** Exception: user error (Pattern match failure in do expression at Traced.hs:193:3-6)
41-- > Trace:
41-- > Trace:
42−-- > 0 False
43−-- > 1 Left 1
42+-- > 0 Left 1
44module Traced ( MonadS(..)
43module Traced ( MonadS(..)
45 , return
44 , return
46 , (>>=)
45 , (>>=)
@@ -54,6 +53,7 @@ import Prelude hiding ((>>=), return, fail, catch, (>>))
54import qualified Prelude
53import qualified Prelude
55import Data.String (fromString)
54import Data.String (fromString)
56import Control.Exception (catches, Handler(..), SomeException, throw, Exception(..), IOException)
55import Control.Exception (catches, Handler(..), SomeException, throw, Exception(..), IOException)
56+import Control.Applicative ((<$>))
57import Data.Typeable (Typeable)
57import Data.Typeable (Typeable)
58import Data.Maybe (catMaybes)
58import Data.Maybe (catMaybes)
59import Data.List (intersperse)
59import Data.List (intersperse)
@@ -98,8 +98,8 @@ class Trace a where
98 trace :: a -> Maybe String
98 trace :: a -> Maybe String
99
99
100instance (Trace a, Trace b) => Trace (Either a b) where
100instance (Trace a, Trace b) => Trace (Either a b) where
101− trace (Left x) = trace x
101+ trace (Left x) = ("Left " ++) <$> trace x
102− trace (Right y) = trace y
102+ trace (Right y) = ("Right " ++) <$> trace y
103
103
104instance Trace a => Trace [a] where
104instance Trace a => Trace [a] where
105 trace as = Just $ "[" ++ (concat . intersperse "," . catMaybes . map trace $ as) ++ "]"
105 trace as = Just $ "[" ++ (concat . intersperse "," . catMaybes . map trace $ as) ++ "]"