-- | See the package page for a short tutorial.


module Debug.Trace.FunctionCall where

import Debug.Trace

class Traceable a
  where traceFunction :: String -> a -> a
        -- ^ Display the parameters and result of evaluating the function when its result is forced. The first argument is the name
        -- of the function, as it should appear in the debugging output. The second parameter is the original function.
instance Show a => Traceable a
  where traceFunction n x = trace (n ++ " = " ++ show x) x
instance (Showable a, Traceable b) => Traceable (a -> b)
  where traceFunction n f x = traceFunction (n ++ " " ++ showFunction x) (f x)

class Showable a where showFunction :: a -> String
instance Show a => Showable a where showFunction x = showsPrec 11 x ""
instance Showable (a -> b) where showFunction _ = "_"