summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <pngwjpgh@users.noreply.github.com>2016-08-05 12:36:29 +0200
committerGregor Kleen <pngwjpgh@users.noreply.github.com>2016-08-05 12:36:29 +0200
commit10be4c21eba0c4df2d2cf03f2d5adb547fb08e0a (patch)
tree9b67145edcf29e633169515cb3d49d8168f48658
parent5597e2f90b1e093a3b4dd110a84d40173e9abc77 (diff)
downloadevents-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.hs24
-rw-r--r--events/src/Events/Spec/Eval.hs23
-rw-r--r--events/src/Events/Spec/Types.hs35
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
3module Events.Spec 3module 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
13import Events.Spec.Parse 13import Events.Spec.Parse
14 14
15import Control.Monad ((<=<))
16import Control.Monad.IO.Class
17import Control.Monad.State.Lazy
18 15
19import Data.Monoid 16import Data.Conduit
20import Data.Foldable
21import Control.Lens
22 17
23import Debug.Trace 18import Data.Text (Text)
19import qualified Data.Text as T
24 20
25interpret :: MonadIO m => Spec m -> Eval m () 21import Control.Monad.Catch (MonadThrow)
26interpret = join . fmap interpretCmnd . evalExpr
27 22
28interpretCmnd :: MonadIO m => Cmnd -> Eval m () 23
29interpretCmnd (COverride obj) = objPayload ?= obj 24interpret :: MonadThrow m => Producer m Text -> Eval m ()
30interpretCmnd (COccurs b) = objOccurs .= b 25interpret source = evalExpr =<< lift (connect source parse)
31interpretCmnd _ = 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
5module Events.Spec.Eval 3module Events.Spec.Eval
6 ( evalExpr 4 ( evalExpr
7 , Bindable(..)
8 ) where 5 ) where
9 6
10import Events.Spec.Types 7import Events.Spec.Types
@@ -42,23 +39,3 @@ evalExpr (EVal a) = a
42evalExpr (ELam a) = a 39evalExpr (ELam a) = a
43evalExpr (EApp (ELam (EPri f)) a) = evalExpr . f $ evalExpr a 40evalExpr (EApp (ELam (EPri f)) a) = evalExpr . f $ evalExpr a
44evalExpr (EApp f a) = evalExpr $ beta a (evalExpr f) 41evalExpr (EApp f a) = evalExpr $ beta a (evalExpr f)
45
46type family Ctx m f where
47 Ctx m (m a -> b) = (a ': Ctx m b)
48 Ctx m a = '[]
49
50type 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
55class Bindable m b where
56 liftE :: (Val m a -> b) -> Expr m (a ': Ctx m b) (Fin m b)
57
58instance ((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
62instance {-# 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
3module Events.Spec.Types 5module 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
29type Spec m = Expr (Eval m) '[] Cmnd 31type family Ctx m f where
32 Ctx m (m a -> b) = (a ': Ctx m b)
33 Ctx m a = '[]
34
35type 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
40class Bindable m a where
41 liftE :: a -> Expr m (Ctx m a) (Fin m a)
42
43instance (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
47instance {-# 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
51instance (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
56type Spec m = Expr (Eval m) '[] ()
30 57
31data Cmnd = COverride Object
32 | COccurs Bool
33 | CNop
34 deriving (Show)
35 58
36data Elem :: a -> [a] -> * where 59data Elem :: a -> [a] -> * where
37 EZ :: Elem x (x ': xs) 60 EZ :: Elem x (x ': xs)