boltzmann-brain
boltzmann-brain copied to clipboard
Compilation error with bb-build
bb-build
fails to compile the following grammar:
@module Sampler
@size 1000
@generate Tree
Tree = Node [Tree].
bb-compile
runs smoothly but when trying to compile the generated module I get:
/path/to/Sampler.hs:30:8: error:
• Not in scope: ‘TH.lift’
No module named ‘TH’ is imported.
• In the untyped splice:
$(TH.lift (decisionTree [0.49974987493747]))
|
30 | = $( TH.lift (decisionTree [0.49974987493747]) )
| ^^^^^^^
I'll give the generated file below so you can have a look
My setup:
$ python -c 'import paganini; print(paganini.__version__)'
1.4.0
$ git log --oneline | head -n 1
a85fcc3 Update link
-- | Compiler: Boltzmann Brain v2.0 (01-07-2022 19:31:23)
-- | Generated at: 01-07-2022 19:58:32
-- | Singularity: 0.249999937437454
-- | System type: algebraic
-- | Target size: 1000
-- | Stability: experimental
{-# LANGUAGE TemplateHaskell, DeriveGeneric, DeriveAnyClass #-}
module Sampler
(Tree(), genRandomTree, genRandomTreeList, sample, sampleTreeIO,
sampleTreeListIO)
where
import GHC.Generics
import Data.Aeson
import Control.Monad (guard)
import Control.Monad.Trans (lift)
import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
import Data.Buffon.Machine
(BuffonMachine, DecisionTree(..), decisionTree, choiceDDG, runRIO)
import Data.Vector (Vector(..), fromList)
import System.Random (RandomGen(..))
newtype Tree = Node [Tree]
deriving (Generic, ToJSON, FromJSON, Show)
ddgTree :: Vector Int
ddgTree = $( [|fromList []|] )
decisionTreeListTree :: DecisionTree Int
decisionTreeListTree
= $( TH.lift (decisionTree [0.49974987493747]) )
genRandomTree ::
(RandomGen g) => Int -> MaybeT (BuffonMachine g) (Tree, Int)
genRandomTree ub
= do guard (ub > 0)
(x0, w0) <- genRandomTreeList (ub - 1)
return (Node x0, 1 + w0)
genRandomTreeList ::
(RandomGen g) => Int -> MaybeT (BuffonMachine g) ([Tree], Int)
genRandomTreeList ub
= do guard (ub > 0)
n <- lift (choiceDDG ddgTree)
case n of
0 -> do (x, w) <- genRandomTree ub
(xs, ws) <- genRandomTreeList (ub - w)
return (x : xs, w + ws)
_ -> return ([], 0)
sample ::
(RandomGen g) =>
(Int -> MaybeT (BuffonMachine g) (a, Int)) ->
Int -> Int -> BuffonMachine g a
sample gen lb ub
= do str <- runMaybeT (gen ub)
case str of
Nothing -> sample gen lb ub
Just (x, s) -> if lb <= s && s <= ub then return x else
sample gen lb ub
sampleTreeIO :: Int -> Int -> IO Tree
sampleTreeIO lb ub = runRIO (sample genRandomTree lb ub)
sampleTreeListIO :: Int -> Int -> IO [Tree]
sampleTreeListIO lb ub = runRIO (sample genRandomTreeList lb ub)