module Mcmc.Trace
( Trace,
singletonT,
pushT,
headT,
takeT,
)
where
import Data.Aeson
import Mcmc.Item
newtype Trace a = Trace {fromTrace :: [Item a]}
deriving (Show, Read, Eq)
instance Semigroup (Trace a) where
(Trace l) <> (Trace r) = Trace (l <> r)
instance Monoid (Trace a) where
mempty = Trace []
instance ToJSON a => ToJSON (Trace a) where
toJSON (Trace xs) = toJSON xs
toEncoding (Trace xs) = toEncoding xs
instance FromJSON a => FromJSON (Trace a) where
parseJSON v = Trace <$> parseJSONList v
singletonT :: Item a -> Trace a
singletonT i = Trace [i]
pushT :: Item a -> Trace a -> Trace a
pushT x = Trace . (:) x . fromTrace
{-# INLINEABLE pushT #-}
headT :: Trace a -> Item a
headT = head . fromTrace
takeT :: Int -> Trace a -> [Item a]
takeT n = take n . fromTrace