diff options
author | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-08-05 13:21:32 +0200 |
---|---|---|
committer | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-08-05 13:21:32 +0200 |
commit | f5311120a05081ee67de73057f1057e6f54b40e2 (patch) | |
tree | 11688cb6c0f28e3aa7a946c188b4fdf8f7b76433 | |
parent | 10be4c21eba0c4df2d2cf03f2d5adb547fb08e0a (diff) | |
download | events-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.hs | 6 | ||||
-rw-r--r-- | events/src/Events/Types.hs | 2 | ||||
-rw-r--r-- | events/src/Events/Types/NDT.hs | 4 |
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 | ||
3 | module Events.Spec | 3 | module 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 | |||
21 | import Control.Monad.Catch (MonadThrow) | 21 | import Control.Monad.Catch (MonadThrow) |
22 | 22 | ||
23 | 23 | ||
24 | interpret :: MonadThrow m => Producer m Text -> Eval m () | 24 | interpret :: Monad m => Sink (Spec m) (Eval m) () |
25 | interpret source = evalExpr =<< lift (connect source parse) | 25 | interpret = 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 | ||
28 | import Control.Monad.State.Lazy | 28 | import Control.Monad.State.Lazy |
29 | import Control.Monad.Reader | 29 | import Control.Monad.Reader |
30 | import Control.Monad.Catch (MonadThrow) | ||
30 | 31 | ||
31 | import Control.Applicative (Alternative(..)) | 32 | import 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 | ||
85 | instance MonadTrans Eval where | 87 | instance 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 | |||
24 | import Control.Monad.Trans | 24 | import Control.Monad.Trans |
25 | import Control.Monad.Reader (MonadReader(..)) | 25 | import Control.Monad.Reader (MonadReader(..)) |
26 | import Control.Monad.Trans.Maybe | 26 | import Control.Monad.Trans.Maybe |
27 | import Control.Monad.Catch (MonadThrow(..)) | ||
27 | 28 | ||
28 | import Debug.Trace | 29 | import Debug.Trace |
29 | 30 | ||
@@ -72,6 +73,9 @@ instance MonadReader r m => MonadReader r (NDT m) where | |||
72 | instance MonadIO m => MonadIO (NDT m) where | 73 | instance MonadIO m => MonadIO (NDT m) where |
73 | liftIO = lift . liftIO | 74 | liftIO = lift . liftIO |
74 | 75 | ||
76 | instance MonadThrow m => MonadThrow (NDT m) where | ||
77 | throwM = lift . throwM | ||
78 | |||
75 | empty :: Applicative m => NDT m a | 79 | empty :: Applicative m => NDT m a |
76 | empty = NDTCons $ pure Nothing | 80 | empty = NDTCons $ pure Nothing |
77 | 81 | ||