traced-3000: Simple evaluation trace

Copyright (C) 2014-15 Edward Kmett, 2008-2009 Lennart Augustsson BSD-style (see the file LICENSE) Edward Kmett provisional portable None Haskell2010

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

 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) Typeable (* -> *) Traced (Traceable a, Liftable b tb) => Liftable (a -> b) (Traced a -> tb)

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

Create a traced value.

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

Create a named traced value.

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

Add a named to a traced value.

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

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

unTraced :: Traced a -> a Source

Extract the real value from a traced value.

tracedD :: Traceable a => Traced a -> TracedD Source

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

Minimal complete definition

trPPrint

Instances

 (Typeable * a, Show a) => Traceable a

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

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

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

Minimal complete definition

liftT'

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 -> String Source

Show the expression tree of a traced value.

showAsExpFull :: Traceable a => Traced a -> String Source

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

simplify :: Traced a -> Traced a Source

Simplify an expression tree.

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

Traced version of if.

(%==) :: (Traceable a, Eq a) => Traced a -> Traced a -> Traced Bool infix 4 Source

Comparisons generating traced booleans.

(%/=) :: (Traceable a, Eq a) => Traced a -> Traced a -> Traced Bool infix 4 Source

Comparisons generating traced booleans.

(%<) :: (Traceable a, Ord a) => Traced a -> Traced a -> Traced Bool infix 4 Source

(%<=) :: (Traceable a, Ord a) => Traced a -> Traced a -> Traced Bool infix 4 Source

(%>) :: (Traceable a, Ord a) => Traced a -> Traced a -> Traced Bool infix 4 Source

(%>=) :: (Traceable a, Ord a) => Traced a -> Traced a -> Traced Bool infix 4 Source

data TracedExp a Source

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

Instances

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