traced-2009.7.20: Simple evaluation trace

Debug.Traced

Description

The Traced module provides a simple way of tracing expression evaluation. A value of type `Traced a` has both a value of type `a` and an expression tree that describes how the value was computed.

There are instances for the `Traced` type for all numeric classes to make it simple to trace numeric expressions.

The expression tree associated with a traced value is exactly that: a tree. But evaluation of expressions in Haskell typically has sharing to avoid recomputation. This sharing can be recovered by the (impure) `reShare` function.

\$examples

Synopsis

Documentation

data Traced a Source

Traced values of some type.

Instances

 Typeable1 Traced Liftable Bool (Traced Bool) Liftable Double (Traced Double) Liftable Float (Traced Float) Liftable Int (Traced Int) Liftable Integer (Traced Integer) Liftable Ordering (Traced Ordering) Liftable () (Traced ()) (Traceable a, Enum a) => Enum (Traced a) Eq a => Eq (Traced a) (Traceable a, Floating a) => Floating (Traced a) (Traceable a, Fractional a) => Fractional (Traced a) (Traceable a, Integral a) => Integral (Traced a) Data a => Data (Traced a) (Traceable a, Num a) => Num (Traced a) Ord a => Ord (Traced a) (Read a, Traceable a) => Read (Traced a) (Traceable a, Real a) => Real (Traced a) (Traceable a, RealFloat a) => RealFloat (Traced a) (Traceable a, RealFrac a) => RealFrac (Traced a) Show a => Show (Traced a) (Traceable a, Liftable b tb) => Liftable (a -> b) (Traced a -> tb)

traced :: Traceable a => a -> Traced aSource

Create a traced value.

named :: Traceable a => String -> a -> Traced aSource

Create a named traced value.

nameTraced :: Traceable a => String -> Traced a -> Traced aSource

Add a named to a traced value.

unknown :: Traceable a => String -> Traced aSource

Create a named thing with no value. Cannot be used where a real value is needed.

unTraced :: Traced a -> aSource

Extract the real value from a traced value.

tracedD :: Traceable a => Traced a -> TracedDSource

Extract the expression tree from a traced value.

data TracedD Source

Expression tree for a traced value.

Instances

 Eq TracedD Data TracedD Ord TracedD Show TracedD Typeable TracedD

unTracedD :: Traceable a => TracedD -> Maybe (Traced a)Source

Convert an expression tree to a traced value, if the types are correct.

class (Typeable a, Show a) => Traceable a Source

Instances

 (Typeable a, Show a) => Traceable a

liftT :: Liftable a b => Name -> Fixity -> a -> bSource

liftFun :: Liftable a b => Name -> a -> bSource

class Liftable a b | a -> b, b -> aSource

Instances

 Liftable Bool (Traced Bool) Liftable Double (Traced Double) Liftable Float (Traced Float) Liftable Int (Traced Int) Liftable Integer (Traced Integer) Liftable Ordering (Traced Ordering) Liftable () (Traced ()) (Traceable a, Liftable b tb) => Liftable (a -> b) (Traced a -> tb)

showAsExp :: Traceable a => Traced a -> StringSource

Show the expression tree of a traced value.

showAsExpFull :: Traceable a => Traced a -> StringSource

Show the expression tree of a traced value, also show the value of each variable.

simplify :: Traced a -> Traced aSource

Simplify an expression tree.

ifT :: Traceable a => Traced Bool -> Traced a -> Traced a -> Traced aSource

Traced version of if.

(%/=) :: (Traceable a, Eq a) => Traced a -> Traced a -> Traced BoolSource

Comparisons generating traced booleans.

data TracedExp a Source

A wrapper for `Traced` to show it with full details.

Instances

 Typeable1 TracedExp (Enum a, Show a, Typeable a) => Enum (TracedExp a) Eq a => Eq (TracedExp a) (Floating a, Typeable a) => Floating (TracedExp a) (Fractional a, Typeable a) => Fractional (TracedExp a) (Integral a, Typeable a) => Integral (TracedExp a) (Num a, Typeable a) => Num (TracedExp a) Ord a => Ord (TracedExp a) (Real a, Typeable a) => Real (TracedExp a) (RealFloat a, Typeable a) => RealFloat (TracedExp a) (RealFrac a, Typeable a) => RealFrac (TracedExp a) (Traceable a, Show a) => Show (TracedExp a)