Skip to content

Commit

Permalink
Use pretty-show when debug tracing actions and models
Browse files Browse the repository at this point in the history
  • Loading branch information
fizruk committed Jun 3, 2018
1 parent fec1122 commit 5ba949b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies:
- monad-control
- mtl
- profunctors
- pretty-show
- servant
- servant-client
- split
Expand Down
15 changes: 8 additions & 7 deletions src/Telegram/Bot/Simple/Debug.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Data.Monoid ((<>))
import qualified Data.Text.Lazy as Text
import qualified Data.Text.Lazy.Encoding as Text
import Debug.Trace (trace)
import Text.Show.Pretty (ppShow)

import qualified Telegram.Bot.API as Telegram
import Telegram.Bot.Simple.BotApp
Expand Down Expand Up @@ -47,7 +48,7 @@ traceTelegramUpdatesJSON = traceTelegramUpdatesWith ppAsJSON

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

-- ** Trace bot actions

Expand All @@ -59,8 +60,8 @@ data TracedAction action

-- | Pretty print 'TraceActionType'.
ppTracedAction :: Show action => TracedAction action -> String
ppTracedAction (TracedIncomingAction action) = "Incoming: " <> show action
ppTracedAction (TracedIssuedAction action) = "Issued: " <> show action
ppTracedAction (TracedIncomingAction action) = "Incoming: " <> ppShow action
ppTracedAction (TracedIssuedAction action) = "Issued: " <> ppShow action

-- | Trace (debug print) every incoming and issued action.
traceBotActionsWith
Expand Down Expand Up @@ -94,18 +95,18 @@ traceBotModelWith
-> BotApp model action
-> BotApp model action
traceBotModelWith f botApp = botApp
{ botInitialModel = traceModel (botInitialModel botApp)
{ botInitialModel = newInitialModel
, botHandler = newHandler
}
where
!newInitialModel = traceModel (botInitialModel botApp)
newHandler action !model = traceModel <$> botHandler botApp action model
traceModel = trace <$> f <*> id

newHandler action model = traceModel <$> botHandler botApp action model

-- | Trace (debug print) bot model using 'Show' instance.
traceBotModelShow
:: Show model => BotApp model action -> BotApp model action
traceBotModelShow = traceBotModelWith show
traceBotModelShow = traceBotModelWith ppShow

-- | Trace (debug print) bot model using 'Show' instance.
traceBotModelJSON
Expand Down
5 changes: 4 additions & 1 deletion telegram-bot-simple.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
--
-- see: https://github.com/sol/hpack
--
-- hash: 2383791691460423691f656814b763382f34aa7b27e58d0417e8c3544729c884
-- hash: 4f2c1b80f5351f2590eeea8c2dc55bf2cc16442fd9da17e54e1467081d5bdcc5

name: telegram-bot-simple
version: 0.1.0
Expand Down Expand Up @@ -63,6 +63,7 @@ library
, http-client-tls
, monad-control
, mtl
, pretty-show
, profunctors
, servant
, servant-client
Expand Down Expand Up @@ -91,6 +92,7 @@ executable example-echo-bot
, http-client-tls
, monad-control
, mtl
, pretty-show
, profunctors
, servant
, servant-client
Expand Down Expand Up @@ -120,6 +122,7 @@ executable example-todo-bot
, http-client-tls
, monad-control
, mtl
, pretty-show
, profunctors
, servant
, servant-client
Expand Down

0 comments on commit 5ba949b

Please sign in to comment.