Skip to content

Commit 5ba949b

Browse files
committed
Use pretty-show when debug tracing actions and models
1 parent fec1122 commit 5ba949b

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dependencies:
3131
- monad-control
3232
- mtl
3333
- profunctors
34+
- pretty-show
3435
- servant
3536
- servant-client
3637
- split

src/Telegram/Bot/Simple/Debug.hs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Data.Monoid ((<>))
99
import qualified Data.Text.Lazy as Text
1010
import qualified Data.Text.Lazy.Encoding as Text
1111
import Debug.Trace (trace)
12+
import Text.Show.Pretty (ppShow)
1213

1314
import qualified Telegram.Bot.API as Telegram
1415
import Telegram.Bot.Simple.BotApp
@@ -47,7 +48,7 @@ traceTelegramUpdatesJSON = traceTelegramUpdatesWith ppAsJSON
4748

4849
-- | Trace (debug print) every update using 'Show' instance.
4950
traceTelegramUpdatesShow :: BotApp model action -> BotApp model action
50-
traceTelegramUpdatesShow = traceTelegramUpdatesWith show
51+
traceTelegramUpdatesShow = traceTelegramUpdatesWith ppShow
5152

5253
-- ** Trace bot actions
5354

@@ -59,8 +60,8 @@ data TracedAction action
5960

6061
-- | Pretty print 'TraceActionType'.
6162
ppTracedAction :: Show action => TracedAction action -> String
62-
ppTracedAction (TracedIncomingAction action) = "Incoming: " <> show action
63-
ppTracedAction (TracedIssuedAction action) = "Issued: " <> show action
63+
ppTracedAction (TracedIncomingAction action) = "Incoming: " <> ppShow action
64+
ppTracedAction (TracedIssuedAction action) = "Issued: " <> ppShow action
6465

6566
-- | Trace (debug print) every incoming and issued action.
6667
traceBotActionsWith
@@ -94,18 +95,18 @@ traceBotModelWith
9495
-> BotApp model action
9596
-> BotApp model action
9697
traceBotModelWith f botApp = botApp
97-
{ botInitialModel = traceModel (botInitialModel botApp)
98+
{ botInitialModel = newInitialModel
9899
, botHandler = newHandler
99100
}
100101
where
102+
!newInitialModel = traceModel (botInitialModel botApp)
103+
newHandler action !model = traceModel <$> botHandler botApp action model
101104
traceModel = trace <$> f <*> id
102105

103-
newHandler action model = traceModel <$> botHandler botApp action model
104-
105106
-- | Trace (debug print) bot model using 'Show' instance.
106107
traceBotModelShow
107108
:: Show model => BotApp model action -> BotApp model action
108-
traceBotModelShow = traceBotModelWith show
109+
traceBotModelShow = traceBotModelWith ppShow
109110

110111
-- | Trace (debug print) bot model using 'Show' instance.
111112
traceBotModelJSON

telegram-bot-simple.cabal

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
--
33
-- see: https://github.com/sol/hpack
44
--
5-
-- hash: 2383791691460423691f656814b763382f34aa7b27e58d0417e8c3544729c884
5+
-- hash: 4f2c1b80f5351f2590eeea8c2dc55bf2cc16442fd9da17e54e1467081d5bdcc5
66

77
name: telegram-bot-simple
88
version: 0.1.0
@@ -63,6 +63,7 @@ library
6363
, http-client-tls
6464
, monad-control
6565
, mtl
66+
, pretty-show
6667
, profunctors
6768
, servant
6869
, servant-client
@@ -91,6 +92,7 @@ executable example-echo-bot
9192
, http-client-tls
9293
, monad-control
9394
, mtl
95+
, pretty-show
9496
, profunctors
9597
, servant
9698
, servant-client
@@ -120,6 +122,7 @@ executable example-todo-bot
120122
, http-client-tls
121123
, monad-control
122124
, mtl
125+
, pretty-show
123126
, profunctors
124127
, servant
125128
, servant-client

0 commit comments

Comments
 (0)