-- |
-- Module: Language.KURE.Debug
-- Copyright: (c) 2012--2021 The University of Kansas
-- License: BSD3
--
-- Maintainer: Neil Sculthorpe <neil.sculthorpe@ntu.ac.uk>
-- Stability: beta
-- Portability: ghc
--
-- This module provides (unsafe) debugging/tracing combinators.
--
module Language.KURE.Debug (
        debugR
) where

import Control.Monad.Fail
import Debug.Trace

import Language.KURE.Combinators.Transform
import Language.KURE.Transform


-- | Trace output of the value being rewritten; use for debugging only.
debugR :: (MonadFail m, Show a) => Int -> String -> Rewrite c m a
debugR :: Int -> String -> Rewrite c m a
debugR Int
n String
msg = (a -> Bool) -> Rewrite c m a
forall (m :: * -> *) a c.
MonadFail m =>
(a -> Bool) -> Rewrite c m a
acceptR (\ a
a -> String -> Bool -> Bool
forall a. String -> a -> a
trace (String
msg String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" : " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String -> String
forall a. Int -> [a] -> [a]
take Int
n (a -> String
forall a. Show a => a -> String
show a
a)) Bool
True)