summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2026-07-09 19:44:18 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2026-07-18 22:59:48 +0200
commitbb7b28a9e8a1a05d6d9af0f943a158a03a148190 (patch)
tree38b65d351826c63715ce573a2a95db78a81f86ae
parentb162d2e23a500bb362aaf2b94d8d3ee8f3651163 (diff)
Expr data type
-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