-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonad.hs
26 lines (21 loc) · 807 Bytes
/
Monad.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{-|
Module : Language.NeuroML.LEMS.Monad
Description : Compiler monad
Copyright : (c) Gautham Ganapathy, 2019
License : BSD
Maintainer : gauthamg@gmail.com
Stability : experimental
Portability : POSIX
LEMS model after being parsed from XML.
-}
module Language.NeuroML.LEMS.Monad where
import Protolude
import Control.Monad.Except (ExceptT, runExceptT)
import Control.Monad.State (StateT, runStateT)
import Control.Monad.Identity (Identity, runIdentity)
type CompilerMonad e s a = ExceptT e (StateT s Identity) a
runCompilerMonad :: s -> CompilerMonad e s a -> Either e s
runCompilerMonad s m = let (ea, s') = (runIdentity . flip runStateT s . runExceptT) m
in case ea of
Left e -> Left e
Right _ -> Right s'