diff options
Diffstat (limited to 'lambda-calcul/haskell/src/Minilang/App.hs')
| -rw-r--r-- | lambda-calcul/haskell/src/Minilang/App.hs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/lambda-calcul/haskell/src/Minilang/App.hs b/lambda-calcul/haskell/src/Minilang/App.hs index 3373b75..0174547 100644 --- a/lambda-calcul/haskell/src/Minilang/App.hs +++ b/lambda-calcul/haskell/src/Minilang/App.hs @@ -20,9 +20,9 @@ import Data.Text.Encoding (decodeUtf8, encodeUtf8) import Data.Time (getCurrentTime) import Minilang.API (Challenge (..), LambdaAPI, Score (..), Token (..), User (..), newToken) import Minilang.Lambda.Parser (pretty) -import Minilang.REPL (withInputs) +import Minilang.REPL (withInputs, replEnvWith) import Minilang.REPL.Purer (PurerEnv (..)) -import Minilang.REPL.Types (Command (..), Content (..), In (..), Out (..), initialREPL) +import Minilang.REPL.Types (Command (..), Content (..), Evaluator (..), In (..), Out (..), initialREPL) import Network.Wai.Application.Static (defaultFileServerSettings, staticApp) import Servant (ServerT, err400, err500, errBody, (:<|>) (..), err404) import Servant.Server (Application, Handler (..), Tagged (..)) @@ -31,15 +31,17 @@ import System.Random (StdGen) data Env = Env { gen :: TVar StdGen, users :: TVar (Map Token Score), - challenges :: [Challenge] + challenges :: [Challenge], + evaluator :: Evaluator } -makeEnv :: StdGen -> [Challenge] -> IO Env -makeEnv gen challenges = +makeEnv :: StdGen -> [Challenge] -> Evaluator -> IO Env +makeEnv gen challenges ev = Env <$> newTVarIO gen <*> newTVarIO mempty <*> pure challenges + <*> pure ev newtype AppM a = AppM {runAppM :: ReaderT Env IO a} deriving newtype (Functor, Applicative, Monad, MonadIO, MonadReader Env) @@ -147,7 +149,8 @@ postAnswer Nothing _ = liftIO $ throwM $ err400 {errBody = "Missing token"} postAnswer (Just token) expected = do checkUserToken token Challenge {expr} <- getCurrentChallenge token - let PurerEnv {outputs} = withInputs initialREPL [Com (Load (Data expr))] + ev <- asks evaluator + let PurerEnv {outputs} = withInputs (replEnvWith ev) [Com (Load (Data expr))] result = evaluateOutputs outputs expected updateUserLastTest token result case result of |
