aboutsummaryrefslogtreecommitdiff
path: root/hsm-repl
diff options
context:
space:
mode:
Diffstat (limited to 'hsm-repl')
-rw-r--r--hsm-repl/Hsm/Repl.hs67
-rw-r--r--hsm-repl/Test/Repl.hs9
2 files changed, 17 insertions, 59 deletions
diff --git a/hsm-repl/Hsm/Repl.hs b/hsm-repl/Hsm/Repl.hs
index 1da7493..dacc76a 100644
--- a/hsm-repl/Hsm/Repl.hs
+++ b/hsm-repl/Hsm/Repl.hs
@@ -4,72 +4,36 @@ module Hsm.Repl
( Repl
, repl
, runRepl
- )
-where
+ ) where
import Control.Monad (forM_)
-import Data.Typeable (Proxy (Proxy), Typeable, typeRep)
-import Effectful (Dispatch (Static), DispatchOf, Eff, IOE, liftIO, (:>))
-import Effectful.Dispatch.Static
- ( SideEffects (WithSideEffects)
- , StaticRep
- , evalStaticRep
- , getStaticRep
- , unsafeEff_
- )
+import Data.Typeable (Proxy(Proxy), Typeable, typeRep)
+import Effectful (Dispatch(Static), DispatchOf, Eff, IOE, (:>), liftIO)
+import Effectful.Dispatch.Static (SideEffects(WithSideEffects), StaticRep, evalStaticRep, getStaticRep, unsafeEff_)
import Effectful.Exception (bracket)
import GHC.TypeLits (KnownSymbol, Symbol, symbolVal)
import Generic.Data.Function.Common.Generic.Meta (KnownSymbols, symbolVals)
-import Hsm.Log (Log, Severity (Attention, Info, Trace), logMsg)
-import Language.Haskell.Interpreter
- ( GhcError (errMsg)
- , InterpreterError (WontCompile)
- , as
- , interpret
- , runInterpreter
- , setImports
- )
-import System.Console.Haskeline
- ( defaultSettings
- , getInputLine
- , handleInterrupt
- , withInterrupt
- )
-import System.Console.Haskeline.IO
- ( InputState
- , cancelInput
- , initializeInput
- , queryInput
- )
+import Hsm.Log (Log, Severity(Attention, Info, Trace), logMsg)
+import Language.Haskell.Interpreter (GhcError(errMsg), InterpreterError(WontCompile), as, interpret, runInterpreter, setImports)
+import System.Console.Haskeline (defaultSettings, getInputLine, handleInterrupt, withInterrupt)
+import System.Console.Haskeline.IO (InputState, cancelInput, initializeInput, queryInput)
data Repl (p :: Symbol) (ms :: [Symbol]) (t :: *) (a :: * -> *) (b :: *)
type instance DispatchOf (Repl p ms t) = Static WithSideEffects
-newtype instance StaticRep (Repl p ms t)
- = Repl InputState
+newtype instance StaticRep (Repl p ms t) =
+ Repl InputState
-repl
- :: forall p ms t es
- . ( KnownSymbol p
- , KnownSymbols ms
- , Log "repl" :> es
- , Repl p ms t :> es
- , Show t
- , Typeable t
- )
+repl ::
+ forall p ms t es. (KnownSymbol p, KnownSymbols ms, Log "repl" :> es, Repl p ms t :> es, Show t, Typeable t)
=> Eff es (Maybe t)
repl = query >>= maybe (return Nothing) parse
where
query = do
Repl inputState <- getStaticRep
logMsg Trace $ "Expecting a value of type: " <> show (typeRep $ Proxy @t)
- unsafeEff_
- . queryInput inputState
- . handleInterrupt (return Nothing)
- . withInterrupt
- . getInputLine $
- symbolVal (Proxy @p)
+ unsafeEff_ . queryInput inputState . handleInterrupt (return Nothing) . withInterrupt . getInputLine $ symbolVal (Proxy @p)
parse string = do
logMsg Trace $ "Parsing string: " <> string
eitherValue <-
@@ -87,9 +51,8 @@ repl = query >>= maybe (return Nothing) parse
logMsg Attention $ show err
repl
-runRepl
- :: forall p ms t es a
- . (IOE :> es, Log "repl" :> es)
+runRepl ::
+ forall p ms t es a. (IOE :> es, Log "repl" :> es)
=> Eff (Repl p ms t : es) a
-> Eff es a
runRepl action = bracket inputStateAlloc inputStateDealloc $ \inputState -> evalStaticRep (Repl inputState) action
diff --git a/hsm-repl/Test/Repl.hs b/hsm-repl/Test/Repl.hs
index 3b0e534..2d299b8 100644
--- a/hsm-repl/Test/Repl.hs
+++ b/hsm-repl/Test/Repl.hs
@@ -1,13 +1,8 @@
-import Control.Monad (void)
import Control.Monad.Loops (whileJust_)
import Data.Function ((&))
import Effectful (runEff)
-import Hsm.Log (Severity (Trace), runLog)
+import Hsm.Log (Severity(Trace), runLog)
import Hsm.Repl (repl, runRepl)
main :: IO ()
-main =
- void (whileJust_ repl return)
- & runRepl @"exec-repl λ " @'["Prelude"] @[Bool]
- & runLog @"repl" Trace
- & runEff
+main = whileJust_ repl return & runRepl @"exec-repl λ " @'[ "Prelude"] @[Bool] & runLog @"repl" Trace & runEff