summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--minici.cabal1
-rw-r--r--src/Expr.hs51
2 files changed, 52 insertions, 0 deletions
diff --git a/minici.cabal b/minici.cabal
index 0a35b53..0bb59a2 100644
--- a/minici.cabal
+++ b/minici.cabal
@@ -47,6 +47,7 @@ executable minici
Config
Destination
Eval
+ Expr
Expression
FileUtils
Job
diff --git a/src/Expr.hs b/src/Expr.hs
new file mode 100644
index 0000000..fa17158
--- /dev/null
+++ b/src/Expr.hs
@@ -0,0 +1,51 @@
+module Expr (
+ Expr(..),
+ ExprContext(..),
+ getContext,
+
+ addDependency,
+ collectDependencies,
+
+ exprIO,
+) where
+
+import Data.Kind
+
+
+data Expr c a where
+ Pure :: a -> Expr c a
+ App :: Expr c (a -> b) -> Expr c a -> Expr c b
+ GetContext :: Expr c c
+ AddDependency :: ExprContext c => ExprDependency c -> Expr c a -> Expr c a
+ ExprIO :: IO a -> Expr c a
+
+instance Functor (Expr c) where
+ fmap f x = Pure f <*> x
+
+instance Applicative (Expr c) where
+ pure = Pure
+ (<*>) = App
+
+
+class Monoid (ExprDependency c) => ExprContext c where
+ type ExprDependency c :: Type
+
+
+getContext :: Expr c c
+getContext = GetContext
+
+
+addDependency :: ExprContext c => ExprDependency c -> Expr c a -> Expr c a
+addDependency = AddDependency
+
+collectDependencies :: ExprContext c => Expr c a -> ExprDependency c
+collectDependencies = \case
+ Pure {} -> mempty
+ App f x -> collectDependencies f <> collectDependencies x
+ GetContext {} -> mempty
+ AddDependency d x -> d <> collectDependencies x
+ ExprIO {} -> mempty
+
+
+exprIO :: IO a -> Expr c a
+exprIO = ExprIO