summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-04-16 17:19:59 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2016-04-16 17:19:59 +0200
commit8581ade929fafc68d1c3e5adde420071f3e0d949 (patch)
tree8f693987c66b2b67f5126d7383dae05f1c58519a
parent63a5c8a5b9bfd5da317c240e16a979fb8e6dc5c6 (diff)
downloadevents-8581ade929fafc68d1c3e5adde420071f3e0d949.tar
events-8581ade929fafc68d1c3e5adde420071f3e0d949.tar.gz
events-8581ade929fafc68d1c3e5adde420071f3e0d949.tar.bz2
events-8581ade929fafc68d1c3e5adde420071f3e0d949.tar.xz
events-8581ade929fafc68d1c3e5adde420071f3e0d949.zip
Introduced some types
-rw-r--r--events/events.cabal11
-rw-r--r--events/events.nix9
-rw-r--r--events/src/Events/Types.hs59
-rw-r--r--events/src/Main.hs2
4 files changed, 78 insertions, 3 deletions
diff --git a/events/events.cabal b/events/events.cabal
index 796742e..3e784af 100644
--- a/events/events.cabal
+++ b/events/events.cabal
@@ -20,6 +20,15 @@ executable events
20 main-is: Main.hs 20 main-is: Main.hs
21 -- other-modules: 21 -- other-modules:
22 -- other-extensions: 22 -- other-extensions:
23 build-depends: base >=4.8 && <4.9 23 build-depends: base >=4.8 && <5
24 , lens >=4.13 && <5
25 , tz >=0.1 && <1
26 , time >=1.5.0 && <2
27 , lens-time >=0.1 && <1
28 , aeson >=0.9 && <1
29 , aeson-lens >=0.5 && <1
30 , mtl >=2.2 && <3
31 , list-t >=0.4.6 && <1
32 , data-default-class >=0.0 && <1
24 hs-source-dirs: src 33 hs-source-dirs: src
25 default-language: Haskell2010 \ No newline at end of file 34 default-language: Haskell2010 \ No newline at end of file
diff --git a/events/events.nix b/events/events.nix
index dba4055..458e78a 100644
--- a/events/events.nix
+++ b/events/events.nix
@@ -1,11 +1,16 @@
1{ mkDerivation, base, stdenv }: 1{ mkDerivation, aeson, aeson-lens, base, data-default-class, lens
2, lens-time, list-t, mtl, stdenv, time, tz
3}:
2mkDerivation { 4mkDerivation {
3 pname = "events"; 5 pname = "events";
4 version = "0.0.0"; 6 version = "0.0.0";
5 src = ./.; 7 src = ./.;
6 isLibrary = false; 8 isLibrary = false;
7 isExecutable = true; 9 isExecutable = true;
8 executableHaskellDepends = [ base ]; 10 executableHaskellDepends = [
11 aeson aeson-lens base data-default-class lens lens-time list-t mtl
12 time tz
13 ];
9 homepage = "https://git.yggdrasil.li/gkleen/pub/events"; 14 homepage = "https://git.yggdrasil.li/gkleen/pub/events";
10 description = "An appointment book"; 15 description = "An appointment book";
11 license = stdenv.lib.licenses.mit; 16 license = stdenv.lib.licenses.mit;
diff --git a/events/src/Events/Types.hs b/events/src/Events/Types.hs
new file mode 100644
index 0000000..55e7a5a
--- /dev/null
+++ b/events/src/Events/Types.hs
@@ -0,0 +1,59 @@
1{-# LANGUAGE TemplateHaskell #-}
2
3module Events.Types
4 ( TimeRange(..), rangeStart, rangeDuration
5 , Event(..), payload, occursWithin
6 , SpecCtx(..), ctxVars
7 , Spec
8 , module Data.Aeson
9 , module Data.Time.Clock
10 , module Data.Default.Class
11 ) where
12
13import Control.Lens.TH
14
15import Data.Aeson (Object)
16
17import Data.Time.Clock
18
19import Control.Monad.Reader
20import ListT (ListT)
21import qualified ListT as ListT
22
23import Data.Default.Class
24
25import Data.Monoid
26import Control.Monad.Fix
27import Control.Lens
28import Data.Maybe
29
30data TimeRange = TimeRange
31 { _rangeStart :: UTCTime
32 , _rangeDuration :: NominalDiffTime
33 }
34makeLenses ''TimeRange
35
36data Event = Event
37 { _payload :: Object
38 , _occursWithin :: TimeRange -> Bool
39 }
40makeLenses ''Event
41
42data SpecCtx = SpecCtx
43 { _ctxVars :: Object
44 , _ctxEvents :: [Event]
45 }
46makeLenses ''SpecCtx
47
48instance Default SpecCtx where
49 def = SpecCtx
50 { _ctxVars = mempty
51 , _ctxEvents = mempty
52 }
53
54type Spec m a = ListT (ReaderT SpecCtx m) a
55
56interpret :: MonadFix m => Spec m (Maybe Event) -> m [Event]
57interpret x = catMaybes <$> mfix x'
58 where
59 x' = runReaderT (ListT.toList x) . flip (set ctxEvents) def . catMaybes
diff --git a/events/src/Main.hs b/events/src/Main.hs
index e9e1deb..1c56140 100644
--- a/events/src/Main.hs
+++ b/events/src/Main.hs
@@ -1,2 +1,4 @@
1import Events.Types
2
1main :: IO () 3main :: IO ()
2main = undefined 4main = undefined