From 8581ade929fafc68d1c3e5adde420071f3e0d949 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 16 Apr 2016 17:19:59 +0200 Subject: Introduced some types --- events/events.cabal | 11 ++++++++- events/events.nix | 9 +++++-- events/src/Events/Types.hs | 59 ++++++++++++++++++++++++++++++++++++++++++++++ events/src/Main.hs | 2 ++ 4 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 events/src/Events/Types.hs 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 main-is: Main.hs -- other-modules: -- other-extensions: - build-depends: base >=4.8 && <4.9 + build-depends: base >=4.8 && <5 + , lens >=4.13 && <5 + , tz >=0.1 && <1 + , time >=1.5.0 && <2 + , lens-time >=0.1 && <1 + , aeson >=0.9 && <1 + , aeson-lens >=0.5 && <1 + , mtl >=2.2 && <3 + , list-t >=0.4.6 && <1 + , data-default-class >=0.0 && <1 hs-source-dirs: src 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 @@ -{ mkDerivation, base, stdenv }: +{ mkDerivation, aeson, aeson-lens, base, data-default-class, lens +, lens-time, list-t, mtl, stdenv, time, tz +}: mkDerivation { pname = "events"; version = "0.0.0"; src = ./.; isLibrary = false; isExecutable = true; - executableHaskellDepends = [ base ]; + executableHaskellDepends = [ + aeson aeson-lens base data-default-class lens lens-time list-t mtl + time tz + ]; homepage = "https://git.yggdrasil.li/gkleen/pub/events"; description = "An appointment book"; 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 @@ +{-# LANGUAGE TemplateHaskell #-} + +module Events.Types + ( TimeRange(..), rangeStart, rangeDuration + , Event(..), payload, occursWithin + , SpecCtx(..), ctxVars + , Spec + , module Data.Aeson + , module Data.Time.Clock + , module Data.Default.Class + ) where + +import Control.Lens.TH + +import Data.Aeson (Object) + +import Data.Time.Clock + +import Control.Monad.Reader +import ListT (ListT) +import qualified ListT as ListT + +import Data.Default.Class + +import Data.Monoid +import Control.Monad.Fix +import Control.Lens +import Data.Maybe + +data TimeRange = TimeRange + { _rangeStart :: UTCTime + , _rangeDuration :: NominalDiffTime + } +makeLenses ''TimeRange + +data Event = Event + { _payload :: Object + , _occursWithin :: TimeRange -> Bool + } +makeLenses ''Event + +data SpecCtx = SpecCtx + { _ctxVars :: Object + , _ctxEvents :: [Event] + } +makeLenses ''SpecCtx + +instance Default SpecCtx where + def = SpecCtx + { _ctxVars = mempty + , _ctxEvents = mempty + } + +type Spec m a = ListT (ReaderT SpecCtx m) a + +interpret :: MonadFix m => Spec m (Maybe Event) -> m [Event] +interpret x = catMaybes <$> mfix x' + where + 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 @@ +import Events.Types + main :: IO () main = undefined -- cgit v1.2.3