Hoed-0.5.1: Lightweight algorithmic debugging.

Safe HaskellNone
LanguageHaskell2010

Debug.Hoed.Observe

Synopsis

Documentation

type UID = Int Source #

data Event Source #

Constructors

Event 

Fields

Instances

Eq Event Source # 

Methods

(==) :: Event -> Event -> Bool #

(/=) :: Event -> Event -> Bool #

Show Event Source # 

Methods

showsPrec :: Int -> Event -> ShowS #

show :: Event -> String #

showList :: [Event] -> ShowS #

Generic Event Source # 

Associated Types

type Rep Event :: * -> * #

Methods

from :: Event -> Rep Event x #

to :: Rep Event x -> Event #

Unbox Event Source # 
Vector Vector Event Source # 
MVector MVector Event Source # 
type Rep Event Source # 
type Rep Event = D1 * (MetaData "Event" "Debug.Hoed.Observe" "Hoed-0.5.1-6GkquCGsp1cHNYyj6cETAl" False) (C1 * (MetaCons "Event" PrefixI True) ((:*:) * (S1 * (MetaSel (Just Symbol "eventParent") SourceUnpack SourceStrict DecidedStrict) (Rec0 * Parent)) (S1 * (MetaSel (Just Symbol "change") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 * Change))))
data Vector Event Source # 
data MVector s Event Source # 

data Change Source #

Constructors

Observe !Text 
Cons !Word8 !Text 
ConsChar !Char 
Enter 
Fun 

Instances

Eq Change Source # 

Methods

(==) :: Change -> Change -> Bool #

(/=) :: Change -> Change -> Bool #

Show Change Source # 
Generic Change Source # 

Associated Types

type Rep Change :: * -> * #

Methods

from :: Change -> Rep Change x #

to :: Rep Change x -> Change #

Unbox Change Source # 
Vector Vector Change Source # 
MVector MVector Change Source # 
type Rep Change Source # 
data Vector Change Source # 
data MVector s Change Source # 

data Parent Source #

Constructors

Parent 

Instances

Eq Parent Source # 

Methods

(==) :: Parent -> Parent -> Bool #

(/=) :: Parent -> Parent -> Bool #

Show Parent Source # 
Generic Parent Source # 

Associated Types

type Rep Parent :: * -> * #

Methods

from :: Parent -> Rep Parent x #

to :: Rep Parent x -> Parent #

Unbox Parent Source # 
Vector Vector Parent Source # 
MVector MVector Parent Source # 
type Rep Parent Source # 
type Rep Parent = D1 * (MetaData "Parent" "Debug.Hoed.Observe" "Hoed-0.5.1-6GkquCGsp1cHNYyj6cETAl" False) (C1 * (MetaCons "Parent" PrefixI True) ((:*:) * (S1 * (MetaSel (Just Symbol "parentUID") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 * UID)) (S1 * (MetaSel (Just Symbol "parentPosition") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 * ParentPosition))))
data Vector Parent Source # 
data MVector s Parent Source # 

class Observable a where Source #

A type class for observable values.

  • For Generic datatypes it can be derived automatically.
  • For opaque datatypes, use observeOpaque or rely on the catch-all ? instance.
  • Custom implementations can exclude one or more fields from the observation:
 instance (Observable a, Observable b) => Observable (excluded, a,b) where
        observe (excluded,a,b) = send "(,,)" (return (,,) excluded << a << b)

Methods

observer :: a -> Parent -> a Source #

observer :: (Generic a, GObservable (Rep a)) => a -> Parent -> a Source #

constrain :: a -> a -> a Source #

constrain :: (Generic a, GConstrain (Rep a)) => a -> a -> a Source #

Instances

Observable Bool Source # 
Observable Char Source # 
Observable Double Source # 
Observable Float Source # 
Observable Int Source # 

Methods

observer :: Int -> Parent -> Int Source #

constrain :: Int -> Int -> Int Source #

Observable Integer Source # 
Observable () Source # 

Methods

observer :: () -> Parent -> () Source #

constrain :: () -> () -> () Source #

Observable Dynamic Source # 
Observable SomeException Source # 
Observable a => Observable [a] Source # 

Methods

observer :: [a] -> Parent -> [a] Source #

constrain :: [a] -> [a] -> [a] Source #

Observable a => Observable (Maybe a) Source # 

Methods

observer :: Maybe a -> Parent -> Maybe a Source #

constrain :: Maybe a -> Maybe a -> Maybe a Source #

Observable a => Observable (IO a) Source # 

Methods

observer :: IO a -> Parent -> IO a Source #

constrain :: IO a -> IO a -> IO a Source #

(Observable a, Observable b) => Observable (a -> b) Source # 

Methods

observer :: (a -> b) -> Parent -> a -> b Source #

constrain :: (a -> b) -> (a -> b) -> a -> b Source #

(Observable a, Observable b) => Observable (Either a b) Source # 

Methods

observer :: Either a b -> Parent -> Either a b Source #

constrain :: Either a b -> Either a b -> Either a b Source #

(Observable a, Observable b) => Observable (a, b) Source # 

Methods

observer :: (a, b) -> Parent -> (a, b) Source #

constrain :: (a, b) -> (a, b) -> (a, b) Source #

(Ix a, Observable a, Observable b) => Observable (Array a b) Source # 

Methods

observer :: Array a b -> Parent -> Array a b Source #

constrain :: Array a b -> Array a b -> Array a b Source #

(Observable a, Observable b, Observable c) => Observable (a, b, c) Source # 

Methods

observer :: (a, b, c) -> Parent -> (a, b, c) Source #

constrain :: (a, b, c) -> (a, b, c) -> (a, b, c) Source #

(Observable a, Observable b, Observable c, Observable d) => Observable (a, b, c, d) Source # 

Methods

observer :: (a, b, c, d) -> Parent -> (a, b, c, d) Source #

constrain :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) Source #

(Observable a, Observable b, Observable c, Observable d, Observable e) => Observable (a, b, c, d, e) Source # 

Methods

observer :: (a, b, c, d, e) -> Parent -> (a, b, c, d, e) Source #

constrain :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) Source #

class GObservable f where Source #

Minimal complete definition

gdmobserver, gdmObserveArgs, gdmShallowShow

Methods

gdmobserver :: f a -> Parent -> f a Source #

gdmObserveArgs :: f a -> ObserverM (f a) Source #

gdmShallowShow :: f a -> Text Source #

Instances

GObservable (U1 *) Source # 
Observable a => GObservable (K1 * i a) Source # 

Methods

gdmobserver :: K1 * i a a -> Parent -> K1 * i a a Source #

gdmObserveArgs :: K1 * i a a -> ObserverM (K1 * i a a) Source #

gdmShallowShow :: K1 * i a a -> Text Source #

(GObservable a, GObservable b) => GObservable ((:+:) * a b) Source # 

Methods

gdmobserver :: (* :+: a) b a -> Parent -> (* :+: a) b a Source #

gdmObserveArgs :: (* :+: a) b a -> ObserverM ((* :+: a) b a) Source #

gdmShallowShow :: (* :+: a) b a -> Text Source #

(GObservable a, GObservable b) => GObservable ((:*:) * a b) Source # 

Methods

gdmobserver :: (* :*: a) b a -> Parent -> (* :*: a) b a Source #

gdmObserveArgs :: (* :*: a) b a -> ObserverM ((* :*: a) b a) Source #

gdmShallowShow :: (* :*: a) b a -> Text Source #

(FieldLimit (S (S (S (S (S (S Z)))))) a, GObservable a) => GObservable (M1 * D d a) Source # 

Methods

gdmobserver :: M1 * D d a a -> Parent -> M1 * D d a a Source #

gdmObserveArgs :: M1 * D d a a -> ObserverM (M1 * D d a a) Source #

gdmShallowShow :: M1 * D d a a -> Text Source #

(GObservable a, Constructor Meta c) => GObservable (M1 * C c a) Source # 

Methods

gdmobserver :: M1 * C c a a -> Parent -> M1 * C c a a Source #

gdmObserveArgs :: M1 * C c a a -> ObserverM (M1 * C c a a) Source #

gdmShallowShow :: M1 * C c a a -> Text Source #

(GObservable a, Selector Meta s) => GObservable (M1 * S s a) Source # 

Methods

gdmobserver :: M1 * S s a a -> Parent -> M1 * S s a a Source #

gdmObserveArgs :: M1 * S s a a -> ObserverM (M1 * S s a a) Source #

gdmShallowShow :: M1 * S s a a -> Text Source #

constrainBase :: (Show a, Eq a) => a -> a -> a Source #

class GConstrain f where Source #

Minimal complete definition

gconstrain

Methods

gconstrain :: f a -> f a -> f a Source #

Instances

GConstrain (U1 *) Source # 

Methods

gconstrain :: U1 * a -> U1 * a -> U1 * a Source #

Observable a => GConstrain (K1 * i a) Source # 

Methods

gconstrain :: K1 * i a a -> K1 * i a a -> K1 * i a a Source #

(GConstrain a, GConstrain b) => GConstrain ((:+:) * a b) Source # 

Methods

gconstrain :: (* :+: a) b a -> (* :+: a) b a -> (* :+: a) b a Source #

(GConstrain a, GConstrain b) => GConstrain ((:*:) * a b) Source # 

Methods

gconstrain :: (* :*: a) b a -> (* :*: a) b a -> (* :*: a) b a Source #

GConstrain a => GConstrain (M1 * D d a) Source # 

Methods

gconstrain :: M1 * D d a a -> M1 * D d a a -> M1 * D d a a Source #

(GConstrain a, Constructor Meta c) => GConstrain (M1 * C c a) Source # 

Methods

gconstrain :: M1 * C c a a -> M1 * C c a a -> M1 * C c a a Source #

(GConstrain a, Selector Meta s) => GConstrain (M1 * S s a) Source # 

Methods

gconstrain :: M1 * S s a a -> M1 * S s a a -> M1 * S s a a Source #

gdmFunObserver :: (Observable a, Observable b) => Parent -> (a -> b) -> a -> b Source #

observeBase :: Show a => a -> Parent -> a Source #

observeOpaque :: Text -> a -> Parent -> a Source #

newtype ObserverM a Source #

Constructors

ObserverM 

Fields

Instances

Monad ObserverM Source # 

Methods

(>>=) :: ObserverM a -> (a -> ObserverM b) -> ObserverM b #

(>>) :: ObserverM a -> ObserverM b -> ObserverM b #

return :: a -> ObserverM a #

fail :: String -> ObserverM a #

Functor ObserverM Source # 

Methods

fmap :: (a -> b) -> ObserverM a -> ObserverM b #

(<$) :: a -> ObserverM b -> ObserverM a #

Applicative ObserverM Source # 

Methods

pure :: a -> ObserverM a #

(<*>) :: ObserverM (a -> b) -> ObserverM a -> ObserverM b #

liftA2 :: (a -> b -> c) -> ObserverM a -> ObserverM b -> ObserverM c #

(*>) :: ObserverM a -> ObserverM b -> ObserverM b #

(<*) :: ObserverM a -> ObserverM b -> ObserverM a #

thunk :: (a -> Parent -> a) -> a -> ObserverM a Source #

gthunk :: GObservable f => f a -> ObserverM (f a) Source #

(<<) :: Observable a => ObserverM (a -> b) -> a -> ObserverM b infixl 9 Source #

gdMapM :: Monad m => (a -> m a) -> m (a -> b) -> a -> m b Source #

gobserve :: (a -> Parent -> a) -> Text -> a -> (a, Int) Source #

observe observes data structures in flight.

An example of use is map (+1) . observe "intermeduate" . map (+2)

In this example, we observe the value that flows from the producer map (+2) to the consumer map (+1).

observe can also observe functions as well a structural values.

observe :: Observable a => Text -> a -> a Source #

Functions which you suspect of misbehaving are annotated with observe and should have a cost centre set. The name of the function, the label of the cost centre and the label given to observe need to be the same.

Consider the following function:

triple x = x + x

This function is annotated as follows:

triple y = (observe "triple" (\x -> {# SCC "triple" #}  x + x)) y

To produce computation statements like:

triple 3 = 6

To observe a value its type needs to be of class Observable. We provided instances for many types already. If you have defined your own type, and want to observe a function that takes a value of this type as argument or returns a value of this type, an Observable instance can be derived as follows:

  data MyType = MyNumber Int | MyName String deriving Generic

  instance Observable MyType

observer_ :: (a -> Parent -> a) -> a -> Parent -> a Source #

gdmobserver_ :: GObservable f => f a -> Parent -> f a Source #

unsafeWithUniq :: (Int -> IO a) -> a Source #

generateContext :: (a -> Parent -> a) -> Text -> a -> (a, Int) Source #

send :: Text -> ObserverM a -> Parent -> a Source #

sendEnterPacket :: (a -> Parent -> a) -> a -> Parent -> a Source #

evaluate :: a -> IO a Source #

ourCatchAllIO :: IO a -> (SomeException -> IO a) -> IO a Source #