From 5ac55d099119008c241d949154f83b17bb1bb915 Mon Sep 17 00:00:00 2001 From: Brent Yorgey Date: Fri, 14 Jun 2024 17:31:35 -0500 Subject: [PATCH] fix type of it variable when using type alias --- src/swarm-tui/Swarm/TUI/Controller.hs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/swarm-tui/Swarm/TUI/Controller.hs b/src/swarm-tui/Swarm/TUI/Controller.hs index ab3315ba08..019899f492 100644 --- a/src/swarm-tui/Swarm/TUI/Controller.hs +++ b/src/swarm-tui/Swarm/TUI/Controller.hs @@ -101,7 +101,7 @@ import Swarm.Language.Pretty import Swarm.Language.Syntax hiding (Key) import Swarm.Language.Typed (Typed (..)) import Swarm.Language.Types -import Swarm.Language.Value (Value (VExc, VKey, VUnit), envTypes, prettyValue) +import Swarm.Language.Value (Value (VExc, VKey, VUnit), envTydefs, envTypes, prettyValue) import Swarm.Log import Swarm.TUI.Controller.Util import Swarm.TUI.Editor.Controller qualified as EC @@ -837,7 +837,8 @@ updateUI = do -- type, and reset the replStatus. | otherwise -> do itIx <- use (gameState . gameControls . replNextValueIndex) - let finalType = stripCmd pty + env <- use (gameState . baseEnv) + let finalType = stripCmd (env ^. envTydefs) pty itName = fromString $ "it" ++ show itIx out = T.intercalate " " [itName, ":", prettyText finalType, "=", into (prettyValue v)] uiState . uiGameplay . uiREPL . replHistory %= addREPLItem (REPLOutput out) @@ -982,11 +983,12 @@ doGoalUpdates = do return goalWasUpdated --- | Strips top-level `cmd` from type (in case of REPL evaluation), --- and returns a boolean to indicate if it happened -stripCmd :: Polytype -> Polytype -stripCmd (Forall xs (TyCmd ty)) = Forall xs ty -stripCmd pty = pty +-- | Strips the top-level @Cmd@ from a type, if any (to compute the +-- result type of a REPL command evaluation). +stripCmd :: TDCtx -> Polytype -> Polytype +stripCmd tdCtx (Forall xs ty) = case whnfType tdCtx ty of + TyCmd resTy -> Forall xs resTy + _ -> Forall xs ty ------------------------------------------------------------ -- REPL events