mirror of
https://github.com/github/semantic.git
synced 2025-01-04 05:27:08 +03:00
Fix Algebra for REPL.
This commit is contained in:
parent
3e6c84a48e
commit
89b8a50737
@ -10,8 +10,8 @@ module Control.Effect.REPL
|
|||||||
|
|
||||||
import Prologue
|
import Prologue
|
||||||
|
|
||||||
import Control.Effect.Carrier
|
import Control.Algebra
|
||||||
import Control.Effect.Reader
|
import Control.Carrier.Reader
|
||||||
import System.Console.Haskeline
|
import System.Console.Haskeline
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
|
||||||
@ -23,10 +23,10 @@ data REPL (m :: * -> *) k
|
|||||||
instance HFunctor REPL
|
instance HFunctor REPL
|
||||||
instance Effect REPL
|
instance Effect REPL
|
||||||
|
|
||||||
prompt :: (Member REPL sig, Carrier sig m) => Text -> m (Maybe Text)
|
prompt :: Has REPL sig m => Text -> m (Maybe Text)
|
||||||
prompt p = send (Prompt p pure)
|
prompt p = send (Prompt p pure)
|
||||||
|
|
||||||
output :: (Member REPL sig, Carrier sig m) => Text -> m ()
|
output :: Has REPL sig m => Text -> m ()
|
||||||
output s = send (Output s (pure ()))
|
output s = send (Output s (pure ()))
|
||||||
|
|
||||||
runREPL :: Prefs -> Settings IO -> REPLC m a -> m a
|
runREPL :: Prefs -> Settings IO -> REPLC m a -> m a
|
||||||
@ -35,13 +35,13 @@ runREPL prefs settings = runReader (prefs, settings) . runREPLC
|
|||||||
newtype REPLC m a = REPLC { runREPLC :: ReaderC (Prefs, Settings IO) m a }
|
newtype REPLC m a = REPLC { runREPLC :: ReaderC (Prefs, Settings IO) m a }
|
||||||
deriving (Functor, Applicative, Monad, MonadIO)
|
deriving (Functor, Applicative, Monad, MonadIO)
|
||||||
|
|
||||||
instance (Carrier sig m, MonadIO m) => Carrier (REPL :+: sig) (REPLC m) where
|
instance (Algebra sig m, MonadIO m) => Algebra (REPL :+: sig) (REPLC m) where
|
||||||
eff (L op) = do
|
alg (L op) = do
|
||||||
args <- REPLC ask
|
args <- REPLC ask
|
||||||
case op of
|
case op of
|
||||||
Prompt p k -> liftIO (uncurry runInputTWithPrefs args (fmap (fmap T.pack) (getInputLine (cyan <> T.unpack p <> plain)))) >>= k
|
Prompt p k -> liftIO (uncurry runInputTWithPrefs args (fmap (fmap T.pack) (getInputLine (cyan <> T.unpack p <> plain)))) >>= k
|
||||||
Output s k -> liftIO (uncurry runInputTWithPrefs args (outputStrLn (T.unpack s))) *> k
|
Output s k -> liftIO (uncurry runInputTWithPrefs args (outputStrLn (T.unpack s))) *> k
|
||||||
eff (R other) = REPLC (eff (R (handleCoercible other)))
|
alg (R other) = REPLC (alg (R (handleCoercible other)))
|
||||||
|
|
||||||
|
|
||||||
cyan :: String
|
cyan :: String
|
||||||
|
Loading…
Reference in New Issue
Block a user