diff options
author | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-08-05 12:36:29 +0200 |
---|---|---|
committer | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-08-05 12:36:29 +0200 |
commit | 10be4c21eba0c4df2d2cf03f2d5adb547fb08e0a (patch) | |
tree | 9b67145edcf29e633169515cb3d49d8168f48658 | |
parent | 5597e2f90b1e093a3b4dd110a84d40173e9abc77 (diff) | |
download | events-10be4c21eba0c4df2d2cf03f2d5adb547fb08e0a.tar events-10be4c21eba0c4df2d2cf03f2d5adb547fb08e0a.tar.gz events-10be4c21eba0c4df2d2cf03f2d5adb547fb08e0a.tar.bz2 events-10be4c21eba0c4df2d2cf03f2d5adb547fb08e0a.tar.xz events-10be4c21eba0c4df2d2cf03f2d5adb547fb08e0a.zip |
cleanup
-rw-r--r-- | events/src/Events/Spec.hs | 24 | ||||
-rw-r--r-- | events/src/Events/Spec/Eval.hs | 23 | ||||
-rw-r--r-- | events/src/Events/Spec/Types.hs | 35 |
3 files changed, 38 insertions, 44 deletions
diff --git a/events/src/Events/Spec.hs b/events/src/Events/Spec.hs index c2a84ac..f0b1456 100644 --- a/events/src/Events/Spec.hs +++ b/events/src/Events/Spec.hs | |||
@@ -1,8 +1,8 @@ | |||
1 | {-# LANGUAGE GADTs, DataKinds, TypeOperators #-} | 1 | {-# LANGUAGE RankNTypes #-} |
2 | 2 | ||
3 | module Events.Spec | 3 | module Events.Spec |
4 | ( interpret | 4 | ( interpret |
5 | , Spec, Cmnd(..), Expr(..), Elem(..) | 5 | , Spec, Expr(..), 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 |
@@ -12,20 +12,14 @@ import Events.Spec.Eval | |||
12 | 12 | ||
13 | import Events.Spec.Parse | 13 | import Events.Spec.Parse |
14 | 14 | ||
15 | import Control.Monad ((<=<)) | ||
16 | import Control.Monad.IO.Class | ||
17 | import Control.Monad.State.Lazy | ||
18 | 15 | ||
19 | import Data.Monoid | 16 | import Data.Conduit |
20 | import Data.Foldable | ||
21 | import Control.Lens | ||
22 | 17 | ||
23 | import Debug.Trace | 18 | import Data.Text (Text) |
19 | import qualified Data.Text as T | ||
24 | 20 | ||
25 | interpret :: MonadIO m => Spec m -> Eval m () | 21 | import Control.Monad.Catch (MonadThrow) |
26 | interpret = join . fmap interpretCmnd . evalExpr | ||
27 | 22 | ||
28 | interpretCmnd :: MonadIO m => Cmnd -> Eval m () | 23 | |
29 | interpretCmnd (COverride obj) = objPayload ?= obj | 24 | interpret :: MonadThrow m => Producer m Text -> Eval m () |
30 | interpretCmnd (COccurs b) = objOccurs .= b | 25 | interpret source = evalExpr =<< lift (connect source parse) |
31 | interpretCmnd _ = return () | ||
diff --git a/events/src/Events/Spec/Eval.hs b/events/src/Events/Spec/Eval.hs index 9cfb7c1..fdc18c8 100644 --- a/events/src/Events/Spec/Eval.hs +++ b/events/src/Events/Spec/Eval.hs | |||
@@ -1,10 +1,7 @@ | |||
1 | {-# LANGUAGE GADTs, DataKinds, TypeFamilies, TypeOperators, RankNTypes, ScopedTypeVariables #-} | 1 | {-# LANGUAGE GADTs, DataKinds, TypeFamilies, TypeOperators, RankNTypes, ScopedTypeVariables #-} |
2 | {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-} | ||
3 | {-# LANGUAGE InstanceSigs #-} | ||
4 | 2 | ||
5 | module Events.Spec.Eval | 3 | module Events.Spec.Eval |
6 | ( evalExpr | 4 | ( evalExpr |
7 | , Bindable(..) | ||
8 | ) where | 5 | ) where |
9 | 6 | ||
10 | import Events.Spec.Types | 7 | import Events.Spec.Types |
@@ -42,23 +39,3 @@ evalExpr (EVal a) = a | |||
42 | evalExpr (ELam a) = a | 39 | evalExpr (ELam a) = a |
43 | evalExpr (EApp (ELam (EPri f)) a) = evalExpr . f $ evalExpr a | 40 | evalExpr (EApp (ELam (EPri f)) a) = evalExpr . f $ evalExpr a |
44 | evalExpr (EApp f a) = evalExpr $ beta a (evalExpr f) | 41 | evalExpr (EApp f a) = evalExpr $ beta a (evalExpr f) |
45 | |||
46 | type family Ctx m f where | ||
47 | Ctx m (m a -> b) = (a ': Ctx m b) | ||
48 | Ctx m a = '[] | ||
49 | |||
50 | type family Fin m f where | ||
51 | Fin m (m a -> b) = Fin m b | ||
52 | Fin m (m a) = a | ||
53 | Fin m a = a | ||
54 | |||
55 | class Bindable m b where | ||
56 | liftE :: (Val m a -> b) -> Expr m (a ': Ctx m b) (Fin m b) | ||
57 | |||
58 | instance ((Val m b) ~ (m b), Applicative m, Bindable m c) => Bindable m (m b -> c) where | ||
59 | liftE :: (Val m a -> m b -> c) -> Expr m (a ': b ': Ctx m c) (Fin m c) | ||
60 | liftE f = (EPri :: (Val m a -> Expr m (b ': Ctx m c) (Fin m c)) -> Expr m (a ': b ': Ctx m c) (Fin m c)) . ((liftE :: (Val m b -> c) -> Expr m (b ': Ctx m c) (Fin m c)) . ) $ f | ||
61 | |||
62 | instance {-# OVERLAPPABLE #-} (Val m b ~ m b, Ctx m (m b) ~ '[], Fin m (m b) ~ b) => Bindable m (m b) where | ||
63 | liftE :: (Val m a -> Val m b) -> Expr m '[a] b | ||
64 | liftE = EPri . (EVal .) | ||
diff --git a/events/src/Events/Spec/Types.hs b/events/src/Events/Spec/Types.hs index c7fd058..af99f55 100644 --- a/events/src/Events/Spec/Types.hs +++ b/events/src/Events/Spec/Types.hs | |||
@@ -1,10 +1,12 @@ | |||
1 | {-# LANGUAGE GADTs, DataKinds, PolyKinds, TypeOperators, KindSignatures, TypeFamilies, ExplicitNamespaces #-} | 1 | {-# LANGUAGE GADTs, DataKinds, PolyKinds, TypeOperators, KindSignatures, TypeFamilies, ExplicitNamespaces #-} |
2 | {-# LANGUAGE ScopedTypeVariables, MultiParamTypeClasses, FlexibleInstances #-} | ||
3 | {-# LANGUAGE InstanceSigs #-} | ||
2 | 4 | ||
3 | module Events.Spec.Types | 5 | module Events.Spec.Types |
4 | ( Expr(..) | 6 | ( Expr(..) |
5 | , Val(..) | 7 | , Val(..) |
8 | , Bindable(..) | ||
6 | , Spec | 9 | , Spec |
7 | , Cmnd(..) | ||
8 | , Elem(..) | 10 | , Elem(..) |
9 | , Length(..) | 11 | , Length(..) |
10 | , type (++)(..) | 12 | , type (++)(..) |
@@ -26,12 +28,33 @@ type family Val m a where | |||
26 | Val m (a -> b) = Expr m '[a] b | 28 | Val m (a -> b) = Expr m '[a] b |
27 | Val m a = m a | 29 | Val m a = m a |
28 | 30 | ||
29 | type Spec m = Expr (Eval m) '[] Cmnd | 31 | type family Ctx m f where |
32 | Ctx m (m a -> b) = (a ': Ctx m b) | ||
33 | Ctx m a = '[] | ||
34 | |||
35 | type family Fin m f where | ||
36 | Fin m (m a -> b) = Fin m b | ||
37 | Fin m (m a) = a | ||
38 | Fin m a = a | ||
39 | |||
40 | class Bindable m a where | ||
41 | liftE :: a -> Expr m (Ctx m a) (Fin m a) | ||
42 | |||
43 | instance (Val m a ~ m a, Bindable m b) => Bindable m (m a -> b) where | ||
44 | liftE :: (m a -> b) -> Expr m (a ': Ctx m b) (Fin m b) | ||
45 | liftE = (EPri :: (Val m a -> Expr m (Ctx m b) (Fin m b)) -> Expr m (a ': Ctx m b) (Fin m b)) . ((liftE :: b -> Expr m (Ctx m b) (Fin m b)) . ) | ||
46 | |||
47 | instance {-# OVERLAPPABLE #-} (Val m a ~ m a, Val m b ~ m b, Ctx m (m b) ~ '[], Fin m (m b) ~ b) => Bindable m (m a -> m b) where | ||
48 | liftE :: (m a -> m b) -> Expr m '[a] b | ||
49 | liftE = EPri . (EVal .) | ||
50 | |||
51 | instance (Val m a ~ m a, Fin m (m a) ~ a, Ctx m (m a) ~ '[]) => Bindable m (m a) where | ||
52 | liftE :: m a -> Expr m '[] a | ||
53 | liftE = EVal | ||
54 | |||
55 | |||
56 | type Spec m = Expr (Eval m) '[] () | ||
30 | 57 | ||
31 | data Cmnd = COverride Object | ||
32 | | COccurs Bool | ||
33 | | CNop | ||
34 | deriving (Show) | ||
35 | 58 | ||
36 | data Elem :: a -> [a] -> * where | 59 | data Elem :: a -> [a] -> * where |
37 | EZ :: Elem x (x ': xs) | 60 | EZ :: Elem x (x ': xs) |