@@ -2,72 +2,35 @@ module Debug.Trace where
22
33import Prelude
44
5+ import Prim.TypeError (class Warn , Text )
6+
57-- | Nullary class used to raise a custom warning for the debug functions.
68class DebugWarning
79
8- instance warn :: Warn " Debug.Trace usage" => DebugWarning
10+ instance warn :: Warn ( Text " Debug.Trace usage" ) => DebugWarning
911
10- -- | Log a message to the console for debugging purposes and then return a
11- -- | value. The return value is thunked so it is not evaluated until after the
12+ -- | Log any PureScript value to the console for debugging purposes and then
13+ -- | return a value. This will log the value's underlying representation for
14+ -- | low-level debugging, so it may be desireable to `show` the value first.
15+ -- |
16+ -- | The return value is thunked so it is not evaluated until after the
1217-- | message has been printed, to preserve a predictable console output.
1318-- |
1419-- | For example:
1520-- | ``` purescript
1621-- | doSomething = trace "Hello" \_ -> ... some value or computation ...
1722-- | ```
18- trace :: forall a . DebugWarning => String -> (Unit -> a ) -> a
19- trace = traceAny
20-
21- -- | Log a `Show`able value to the console for debugging purposes and then
22- -- | return a value.
23- traceShow :: forall a b . DebugWarning => Show a => a -> (Unit -> b ) -> b
24- traceShow = traceAny <<< show
25-
26- -- | Log any PureScript value to the console for debugging purposes and then
27- -- | return a value. This will log the value's underlying representation for
28- -- | low-level debugging.
29- foreign import traceAny :: forall a b . DebugWarning => a -> (Unit -> b ) -> b
30-
31- -- | Log any value and return it
32- spy :: forall a . DebugWarning => a -> a
33- spy a = traceAny a \_ -> a
23+ foreign import trace :: forall a b . DebugWarning => a -> (Unit -> b ) -> b
3424
3525-- | Log any PureScript value to the console and return the unit value of the
36- -- | Applicative `a`.
37- traceAnyA :: forall a b . DebugWarning => Applicative a => b -> a Unit
38- traceAnyA s = traceAny s \_ -> pure unit
39-
40- -- | Log a message to the console for debugging purposes and then return the
41- -- | unit value of the Applicative `a`.
42- -- |
43- -- | For example:
44- -- | ``` purescript
45- -- | doSomething = do
46- -- | traceA "Hello"
47- -- | ... some value or computation ...
48- -- | ```
49- traceA :: forall a . DebugWarning => Applicative a => String -> a Unit
50- traceA = traceAnyA
51-
52- -- | Log a `Show`able value to the console for debugging purposes and then
53- -- | return the unit value of the Applicative `a`.
54- traceShowA :: forall a b . DebugWarning => Show b => Applicative a => b -> a Unit
55- traceShowA = traceAnyA <<< show
56-
57- -- | Log any PureScript value to the console and return it in `Monad`
58- -- | useful when one has monadic chains
59- -- | ```purescript
60- -- | mbArray :: Maybe (Array Int)
61- -- | foo :: Int
62- -- | foo = fromMaybe zero
63- -- | $ mbArray
64- -- | >>= traceAnyM
65- -- | >>= head
66- -- | >>= traceAnyM
67- -- | ```
68- traceAnyM :: forall m a . DebugWarning => Monad m => a -> m a
69- traceAnyM s = traceAny s \_ -> pure s
70-
71- -- | Same as `traceAnyM` but only for `Show`able values
72- traceShowM :: forall m a . DebugWarning => Show a => Monad m => a -> m a
73- traceShowM s = traceAny (show s) \_ -> pure s
26+ -- | Monad `m`.
27+ traceM :: forall m a . DebugWarning => Monad m => a -> m Unit
28+ traceM s = do
29+ pure unit
30+ trace s \_ -> pure unit
31+
32+ -- | Logs any value and returns it, using a "tag" or key value to annotate the
33+ -- | traced value. Useful when debugging something in the middle of a
34+ -- | expression, as you can insert this into the expression without having to
35+ -- | break it up.
36+ foreign import spy :: forall a . DebugWarning => String -> a -> a
0 commit comments