{-# LANGUAGE RankNTypes #-}
module Mcmc.Monitor.Parameter
(
MonitorParameter (..),
(>$<),
monitorInt,
monitorDouble,
monitorDoubleF,
monitorDoubleS,
)
where
import qualified Data.ByteString.Builder as BB
import Data.Functor.Contravariant
data MonitorParameter a = MonitorParameter
{
forall a. MonitorParameter a -> String
mpName :: String,
forall a. MonitorParameter a -> a -> Builder
mpFunc :: a -> BB.Builder
}
instance Contravariant MonitorParameter where
contramap :: forall a' a. (a' -> a) -> MonitorParameter a -> MonitorParameter a'
contramap a' -> a
f (MonitorParameter String
n a -> Builder
m) = String -> (a' -> Builder) -> MonitorParameter a'
forall a. String -> (a -> Builder) -> MonitorParameter a
MonitorParameter String
n (a -> Builder
m (a -> Builder) -> (a' -> a) -> a' -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a' -> a
f)
monitorInt ::
String ->
MonitorParameter Int
monitorInt :: String -> MonitorParameter Int
monitorInt String
n = String -> (Int -> Builder) -> MonitorParameter Int
forall a. String -> (a -> Builder) -> MonitorParameter a
MonitorParameter String
n Int -> Builder
BB.intDec
monitorDouble ::
String ->
MonitorParameter Double
monitorDouble :: String -> MonitorParameter Double
monitorDouble String
n = String -> (Double -> Builder) -> MonitorParameter Double
forall a. String -> (a -> Builder) -> MonitorParameter a
MonitorParameter String
n (FloatFormat -> Double -> Builder
BB.formatDouble (FloatFormat -> Double -> Builder)
-> FloatFormat -> Double -> Builder
forall a b. (a -> b) -> a -> b
$ Int -> FloatFormat
BB.standard Int
8)
monitorDoubleF ::
String ->
MonitorParameter Double
monitorDoubleF :: String -> MonitorParameter Double
monitorDoubleF String
n = String -> (Double -> Builder) -> MonitorParameter Double
forall a. String -> (a -> Builder) -> MonitorParameter a
MonitorParameter String
n Double -> Builder
BB.doubleDec
monitorDoubleS ::
String ->
MonitorParameter Double
monitorDoubleS :: String -> MonitorParameter Double
monitorDoubleS String
n = String -> (Double -> Builder) -> MonitorParameter Double
forall a. String -> (a -> Builder) -> MonitorParameter a
MonitorParameter String
n (FloatFormat -> Double -> Builder
BB.formatDouble FloatFormat
BB.scientific)