summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <pngwjpgh@users.noreply.github.com>2016-08-05 13:21:32 +0200
committerGregor Kleen <pngwjpgh@users.noreply.github.com>2016-08-05 13:21:32 +0200
commitf5311120a05081ee67de73057f1057e6f54b40e2 (patch)
tree11688cb6c0f28e3aa7a946c188b4fdf8f7b76433
parent10be4c21eba0c4df2d2cf03f2d5adb547fb08e0a (diff)
downloadevents-f5311120a05081ee67de73057f1057e6f54b40e2.tar
events-f5311120a05081ee67de73057f1057e6f54b40e2.tar.gz
events-f5311120a05081ee67de73057f1057e6f54b40e2.tar.bz2
events-f5311120a05081ee67de73057f1057e6f54b40e2.tar.xz
events-f5311120a05081ee67de73057f1057e6f54b40e2.zip
formulate interpret as a Sink
-rw-r--r--events/src/Events/Spec.hs6
-rw-r--r--events/src/Events/Types.hs2
-rw-r--r--events/src/Events/Types/NDT.hs4
3 files changed, 9 insertions, 3 deletions
diff --git a/events/src/Events/Spec.hs b/events/src/Events/Spec.hs
index f0b1456..a4546f8 100644
--- a/events/src/Events/Spec.hs
+++ b/events/src/Events/Spec.hs
@@ -2,7 +2,7 @@
2 2
3module Events.Spec 3module Events.Spec
4 ( interpret 4 ( interpret
5 , Spec, Expr(..), Elem(..) 5 , Spec, Expr(..), Val(..), Bindable(..), Elem(..)
6 , module Events.Spec.Parse 6 , module Events.Spec.Parse
7 , module Events.Spec.Eval 7 , module Events.Spec.Eval
8 ) where 8 ) where
@@ -21,5 +21,5 @@ import qualified Data.Text as T
21import Control.Monad.Catch (MonadThrow) 21import Control.Monad.Catch (MonadThrow)
22 22
23 23
24interpret :: MonadThrow m => Producer m Text -> Eval m () 24interpret :: Monad m => Sink (Spec m) (Eval m) ()
25interpret source = evalExpr =<< lift (connect source parse) 25interpret = maybe (lift mzero) (const interpret <=< lift . evalExpr) =<< await
diff --git a/events/src/Events/Types.hs b/events/src/Events/Types.hs
index 6a8517b..ec4f62d 100644
--- a/events/src/Events/Types.hs
+++ b/events/src/Events/Types.hs
@@ -27,6 +27,7 @@ import Events.Types.NDT (NDT, foldNDT)
27 27
28import Control.Monad.State.Lazy 28import Control.Monad.State.Lazy
29import Control.Monad.Reader 29import Control.Monad.Reader
30import Control.Monad.Catch (MonadThrow)
30 31
31import Control.Applicative (Alternative(..)) 32import Control.Applicative (Alternative(..))
32 33
@@ -80,6 +81,7 @@ newtype Eval m a = Eval { unEval :: StateT ObjCtx (NDT (ReaderT EvalCtx m)) a }
80 , Alternative 81 , Alternative
81 , Monad 82 , Monad
82 , MonadPlus 83 , MonadPlus
84 , MonadThrow
83 ) 85 )
84 86
85instance MonadTrans Eval where 87instance MonadTrans Eval where
diff --git a/events/src/Events/Types/NDT.hs b/events/src/Events/Types/NDT.hs
index f6d3000..848ad39 100644
--- a/events/src/Events/Types/NDT.hs
+++ b/events/src/Events/Types/NDT.hs
@@ -24,6 +24,7 @@ import Control.Monad.Identity
24import Control.Monad.Trans 24import Control.Monad.Trans
25import Control.Monad.Reader (MonadReader(..)) 25import Control.Monad.Reader (MonadReader(..))
26import Control.Monad.Trans.Maybe 26import Control.Monad.Trans.Maybe
27import Control.Monad.Catch (MonadThrow(..))
27 28
28import Debug.Trace 29import Debug.Trace
29 30
@@ -72,6 +73,9 @@ instance MonadReader r m => MonadReader r (NDT m) where
72instance MonadIO m => MonadIO (NDT m) where 73instance MonadIO m => MonadIO (NDT m) where
73 liftIO = lift . liftIO 74 liftIO = lift . liftIO
74 75
76instance MonadThrow m => MonadThrow (NDT m) where
77 throwM = lift . throwM
78
75empty :: Applicative m => NDT m a 79empty :: Applicative m => NDT m a
76empty = NDTCons $ pure Nothing 80empty = NDTCons $ pure Nothing
77 81