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
- data Traced t a
- traced :: (Show a, Typeable a) => a -> Traced t a
- named :: (Show a, Typeable a) => String -> a -> Traced t a
- nameTraced :: String -> Traced t a -> Traced t a
- unknown :: (Show a, Typeable a) => String -> Traced t a
- unTraced :: Traced t a -> a
- tracedD :: Traced t a -> TracedD
- type TracedV a = Traced AsValue a
- data TracedD
- unTracedD :: Typeable a => TracedD -> Maybe (Traced t a)
- liftT :: Liftable a b => Name -> Fixity -> a -> b
- liftFun :: Liftable a b => Name -> a -> b
- class Liftable a b | a -> b
- class Typeable a
- ifT :: (Show a, Typeable a) => Traced t Bool -> Traced t a -> Traced t a -> Traced t a
- (%==) :: Eq a => Traced t a -> Traced t a -> Traced t Bool
- (%/=) :: Eq a => Traced t a -> Traced t a -> Traced t Bool
- (%<) :: Ord a => Traced t a -> Traced t a -> Traced t Bool
- (%<=) :: Ord a => Traced t a -> Traced t a -> Traced t Bool
- (%>) :: Ord a => Traced t a -> Traced t a -> Traced t Bool
- (%>=) :: Ord a => Traced t a -> Traced t a -> Traced t Bool
- data Fixity
- showAsExp :: Show a => Traced t a -> String
- showAsExpFull :: Show a => Traced t a -> String
- reShare :: Typeable a => Traced t a -> Traced t a
- simplify :: Traced t a -> Traced t a
- type AsValue = Integer
- data AsExp
- data AsFullExp
- asValue :: Traced t a -> Traced AsValue a
- asExp :: Traced t a -> Traced AsExp a
- asFullExp :: Traced t a -> Traced AsFullExp a
- asSharedExp :: Typeable a => Traced t a -> Traced AsExp a
Documentation
Traced values of some type.
Typeable2 Traced | |
Liftable Bool (Traced t Bool) | |
Liftable Double (Traced t Double) | |
Liftable Float (Traced t Float) | |
Liftable Int (Traced t Int) | |
Liftable Integer (Traced t Integer) | |
Liftable Ordering (Traced t Ordering) | |
Liftable () (Traced t ()) | |
(Show a, Typeable a, Enum a) => Enum (Traced t a) | |
Eq a => Eq (Traced t a) | |
(Num t, Typeable a, Floating a) => Floating (Traced t a) | |
(Num t, Typeable a, Fractional a) => Fractional (Traced t a) | |
(Num t, Typeable a, Integral a) => Integral (Traced t a) | |
(Num t, Typeable a, Num a) => Num (Traced t a) | |
Ord a => Ord (Traced t a) | |
(Num t, Typeable a, Real a) => Real (Traced t a) | |
(Num t, Typeable a, RealFloat a) => RealFloat (Traced t a) | |
(Num t, Typeable a, RealFrac a) => RealFrac (Traced t a) | |
(Num t, Show a) => Show (Traced t a) | |
(Typeable a, Show a, Liftable b tb) => Liftable (a -> b) (Traced t a -> tb) |
nameTraced :: String -> Traced t a -> Traced t aSource
Add a named to a traced value.
unknown :: (Show a, Typeable a) => String -> Traced t aSource
Create a named thing with no value. Cannot be used where a real value is needed.
Expression tree for a traced value.
unTracedD :: Typeable a => TracedD -> Maybe (Traced t a)Source
Convert an expression tree to a traced value, if the types are correct.
class Typeable a
The class Typeable
allows a concrete representation of a type to
be calculated.
ifT :: (Show a, Typeable a) => Traced t Bool -> Traced t a -> Traced t a -> Traced t aSource
Traced version of if.
(%/=) :: Eq a => Traced t a -> Traced t a -> Traced t BoolSource
Comparisons generating traced booleans.
showAsExpFull :: Show a => Traced t a -> StringSource
Show the expression tree of a traced value, also show the value of each variable.