git.iko.soy/distributed-process
on master help sign in
Small improvement to Traced
commit706ba610fef910d213e2186e4516025b3bb44b5d authorEdsko de Vries <edsko@edsko.net> dateSat 12 May 2012, 11:33 (14 years ago) parent2fb3b6e
1 file changed+7−7
network-transport-2/tests/Traced.hs+7−7
network-transport-2/tests/Traced.hs+7−7
@@ -19,7 +19,7 @@
1919-- outputs
2020--
2121-- > 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)
2323-- > Trace:
2424-- > 0 Left 2
2525-- > 1 Left 1
@@ -36,11 +36,10 @@
3636--
3737-- The advantage of this idiom is that it gives you line number information when the guard fails:
3838--
39−-- > *Traced> test3
40−-- > *** Exception: user error (Pattern match failure in do expression at tests/Traced.hs:103:3-6)
39+-- > *Traced> test2
40+-- > *** Exception: user error (Pattern match failure in do expression at Traced.hs:193:3-6)
4141-- > Trace:
42−-- > 0 False
43−-- > 1 Left 1
42+-- > 0 Left 1
4443module Traced ( MonadS(..)
4544 , return
4645 , (>>=)
@@ -54,6 +53,7 @@ import Prelude hiding ((>>=), return, fail, catch, (>>))
5453import qualified Prelude
5554import Data.String (fromString)
5655import Control.Exception (catches, Handler(..), SomeException, throw, Exception(..), IOException)
56+import Control.Applicative ((<$>))
5757import Data.Typeable (Typeable)
5858import Data.Maybe (catMaybes)
5959import Data.List (intersperse)
@@ -98,8 +98,8 @@ class Trace a where
9898 trace :: a -> Maybe String
9999
100100instance (Trace a, Trace b) => Trace (Either a b) where
101− trace (Left x) = trace x
102− trace (Right y) = trace y
101+ trace (Left x) = ("Left " ++) <$> trace x
102+ trace (Right y) = ("Right " ++) <$> trace y
103103
104104instance Trace a => Trace [a] where
105105 trace as = Just $ "[" ++ (concat . intersperse "," . catMaybes . map trace $ as) ++ "]"