diff options
-rw-r--r-- | events/events.cabal | 11 | ||||
-rw-r--r-- | events/events.nix | 9 | ||||
-rw-r--r-- | events/src/Events/Types.hs | 59 | ||||
-rw-r--r-- | events/src/Main.hs | 2 |
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 | }: | ||
2 | mkDerivation { | 4 | mkDerivation { |
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 | |||
3 | module 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 | |||
13 | import Control.Lens.TH | ||
14 | |||
15 | import Data.Aeson (Object) | ||
16 | |||
17 | import Data.Time.Clock | ||
18 | |||
19 | import Control.Monad.Reader | ||
20 | import ListT (ListT) | ||
21 | import qualified ListT as ListT | ||
22 | |||
23 | import Data.Default.Class | ||
24 | |||
25 | import Data.Monoid | ||
26 | import Control.Monad.Fix | ||
27 | import Control.Lens | ||
28 | import Data.Maybe | ||
29 | |||
30 | data TimeRange = TimeRange | ||
31 | { _rangeStart :: UTCTime | ||
32 | , _rangeDuration :: NominalDiffTime | ||
33 | } | ||
34 | makeLenses ''TimeRange | ||
35 | |||
36 | data Event = Event | ||
37 | { _payload :: Object | ||
38 | , _occursWithin :: TimeRange -> Bool | ||
39 | } | ||
40 | makeLenses ''Event | ||
41 | |||
42 | data SpecCtx = SpecCtx | ||
43 | { _ctxVars :: Object | ||
44 | , _ctxEvents :: [Event] | ||
45 | } | ||
46 | makeLenses ''SpecCtx | ||
47 | |||
48 | instance Default SpecCtx where | ||
49 | def = SpecCtx | ||
50 | { _ctxVars = mempty | ||
51 | , _ctxEvents = mempty | ||
52 | } | ||
53 | |||
54 | type Spec m a = ListT (ReaderT SpecCtx m) a | ||
55 | |||
56 | interpret :: MonadFix m => Spec m (Maybe Event) -> m [Event] | ||
57 | interpret 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 @@ | |||
1 | import Events.Types | ||
2 | |||
1 | main :: IO () | 3 | main :: IO () |
2 | main = undefined | 4 | main = undefined |