diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2009-05-10 20:18:40 +0100 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2009-05-10 20:18:40 +0100 |
commit | 26750aa4f3adc67a895be14552e31e4423f313c1 (patch) | |
tree | 87059b1070fd65f12f9072fbc845bd0e57033f60 | |
parent | fd5b7c5756710f98567a7dd0ab2df2031422b22f (diff) |
Add an ErrorT to Renderer
-rw-r--r-- | Bustle/Renderer.hs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/Bustle/Renderer.hs b/Bustle/Renderer.hs index f2f4183..61c88c2 100644 --- a/Bustle/Renderer.hs +++ b/Bustle/Renderer.hs @@ -34,6 +34,8 @@ import Data.Map (Map) import Data.Ratio import Control.Applicative ((<$>)) +import Control.Monad.Error +import Control.Monad.Identity import Control.Monad.State import Control.Monad.Writer import Control.Monad (forM_) @@ -43,7 +45,7 @@ import Data.Maybe (fromMaybe, catMaybes) import Data.Ord (comparing) process :: [Message] -> Either String [Shape] -process log = Right $ execRenderer (mapM_ munge log') (initialState initTime) +process log = execRenderer (mapM_ munge log') (initialState initTime) where -- FIXME: really? Maybe we should allow people to be interested in, -- say, binding to signals? @@ -59,11 +61,15 @@ process log = Right $ execRenderer (mapM_ munge log') (initialState initTime) t:_ -> t _ -> 0 -newtype Renderer a = Renderer (WriterT [Shape] (State RendererState) a) - deriving (Functor, Monad, MonadState RendererState, MonadWriter [Shape]) +newtype Renderer a = Renderer (WriterT [Shape] + (StateT RendererState + (ErrorT String Identity) + ) a) + deriving (Functor, Monad, MonadState RendererState, MonadWriter [Shape], + MonadError String) -execRenderer :: Renderer () -> RendererState -> [Shape] -execRenderer (Renderer act) = snd . evalState (runWriterT act) +execRenderer :: Renderer () -> RendererState -> Either String [Shape] +execRenderer (Renderer act) = runIdentity . runErrorT . evalStateT (execWriterT act) data RendererState = RendererState { apps :: Applications |