aboutsummaryrefslogtreecommitdiffstats
path: root/src/Data/JLD/Monad.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/JLD/Monad.hs')
-rw-r--r--src/Data/JLD/Monad.hs86
1 files changed, 0 insertions, 86 deletions
diff --git a/src/Data/JLD/Monad.hs b/src/Data/JLD/Monad.hs
deleted file mode 100644
index 3ae929d..0000000
--- a/src/Data/JLD/Monad.hs
+++ /dev/null
@@ -1,86 +0,0 @@
1module Data.JLD.Monad (
2 JLDT,
3 JLDEnv (..),
4 JLDState (..),
5 newEnv,
6 newState,
7 hoistEnv,
8 modifyContextCache,
9 modifyDocumentCache,
10 JLDET,
11 JLDEEnv (..),
12 JLDEState (..),
13 modifyActiveContext,
14) where
15
16import Data.JLD.Prelude
17
18import Data.JLD.Control.Monad.RES (REST)
19import Data.JLD.Error (JLDError)
20import Data.JLD.Model.ActiveContext (ActiveContext)
21import Data.JLD.Options (ContextCache, DocumentCache, DocumentLoader (..), JLDVersion (..), hoistDocumentLoader)
22
23import Text.URI (URI)
24
25type JLDT e m = REST (JLDEnv e m) (JLDError e) JLDState m
26
27data JLDEnv e m = JLDEnv
28 { jldEnvDocumentLoader :: DocumentLoader e m
29 , jldEnvProcessingMode :: JLDVersion
30 , jldEnvMaxRemoteContexts :: Int
31 }
32 deriving (Show)
33
34data JLDState = JLDState
35 { jldStateContextCache :: ContextCache
36 , jldStateDocumentCache :: DocumentCache
37 }
38 deriving (Show, Eq)
39
40newEnv :: Applicative m => (JLDEnv () m -> JLDEnv e m) -> JLDEnv e m
41newEnv fn =
42 fn
43 JLDEnv
44 { jldEnvDocumentLoader = DocumentLoader (const <. pure <| Left ())
45 , jldEnvProcessingMode = JLD1_1
46 , jldEnvMaxRemoteContexts = 20
47 }
48
49newState :: (JLDState -> JLDState) -> JLDState
50newState fn =
51 fn
52 JLDState
53 { jldStateContextCache = mempty
54 , jldStateDocumentCache = mempty
55 }
56
57hoistEnv :: (forall a. m a -> n a) -> JLDEnv e m -> JLDEnv e n
58hoistEnv map' options = options{jldEnvDocumentLoader = options |> jldEnvDocumentLoader .> hoistDocumentLoader map'}
59
60modifyContextCache :: MonadState JLDState m => (ContextCache -> ContextCache) -> m ()
61modifyContextCache fn = modify \s -> s{jldStateContextCache = fn (jldStateContextCache s)}
62
63modifyDocumentCache :: MonadState JLDState m => (DocumentCache -> DocumentCache) -> m ()
64modifyDocumentCache fn = modify \s -> s{jldStateDocumentCache = fn (jldStateDocumentCache s)}
65
66--
67
68type JLDET e m = REST (JLDEEnv e m) (JLDError e) JLDEState m
69
70data JLDEEnv e m = JLDEEnv
71 { jldeEnvGlobal :: JLDEnv e m
72 , jldeEnvFrameExpansion :: Bool
73 , jldeEnvFromMap :: Bool
74 , jldeEnvBaseUrl :: URI
75 , jldeEnvActiveProperty :: Maybe Text
76 }
77 deriving (Show)
78
79data JLDEState = JLDEState
80 { jldeStateGlobal :: JLDState
81 , jldeStateActiveContext :: ActiveContext
82 }
83 deriving (Show, Eq)
84
85modifyActiveContext :: MonadState JLDEState m => (ActiveContext -> ActiveContext) -> m ()
86modifyActiveContext fn = modify \s -> s{jldeStateActiveContext = fn (jldeStateActiveContext s)}