Language.hs (1312B)
1 {-# LANGUAGE DeriveFunctor #-} 2 3 module Deanie.Language ( 4 -- * types 5 6 ProbF(..) 7 , Prob 8 , ProgramF(..) 9 , Program 10 11 -- * terms 12 13 , bernoulli 14 , beta 15 , gaussian 16 , gamma 17 18 -- * re-export 19 20 , module Control.Applicative.Free 21 , module Control.Monad.Free 22 , module Data.Functor.Sum 23 24 ) where 25 26 import Control.Applicative.Extended (replicateA) 27 import Control.Applicative.Free hiding (Pure) 28 import Control.Monad.Free 29 import Data.Functor.Sum 30 import Prelude hiding (product) 31 32 data ProbF r = 33 BernoulliF {-# UNPACK #-} !Double (Bool -> r) 34 | BetaF {-# UNPACK #-} !Double {-# UNPACK #-} !Double (Double -> r) 35 | GaussianF {-# UNPACK #-} !Double {-# UNPACK #-} !Double (Double -> r) 36 | GammaF {-# UNPACK #-} !Double {-# UNPACK #-} !Double (Double -> r) 37 deriving Functor 38 39 type Prob = Free ProbF 40 41 newtype ProgramF a = ProgramF (Sum ProbF (Ap (Free ProgramF)) a) 42 deriving Functor 43 44 type Program = Free ProgramF 45 46 bernoulli :: Double -> Program Bool 47 bernoulli p = liftF (ProgramF (InL (BernoulliF p id))) 48 49 beta :: Double -> Double -> Program Double 50 beta a b = liftF (ProgramF (InL (BetaF a b id))) 51 52 gamma :: Double -> Double -> Program Double 53 gamma a b = liftF (ProgramF (InL (GammaF a b id))) 54 55 gaussian :: Double -> Double -> Program Double 56 gaussian m s = liftF (ProgramF (InL (GaussianF m s id))) 57