diff options
| author | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-10-28 20:14:16 +0100 |
|---|---|---|
| committer | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-10-28 20:14:16 +0100 |
| commit | 1d1f0efc7de1eaa0c8a6b503892c2f950008fde6 (patch) | |
| tree | bd2e2ea5963d8a208d302854502f580d8ffd73cb /lambda-calcul/haskell/src/Minilang/Lambda/Infer.hs | |
| parent | a210419fd60c00d011f70fb1b968031621e4c01a (diff) | |
| download | lambda-nantes-1d1f0efc7de1eaa0c8a6b503892c2f950008fde6.tar.gz | |
wip: port REPL from minilang
Diffstat (limited to 'lambda-calcul/haskell/src/Minilang/Lambda/Infer.hs')
| -rw-r--r-- | lambda-calcul/haskell/src/Minilang/Lambda/Infer.hs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/lambda-calcul/haskell/src/Minilang/Lambda/Infer.hs b/lambda-calcul/haskell/src/Minilang/Lambda/Infer.hs index 415849a..94fecb3 100644 --- a/lambda-calcul/haskell/src/Minilang/Lambda/Infer.hs +++ b/lambda-calcul/haskell/src/Minilang/Lambda/Infer.hs @@ -48,14 +48,14 @@ typeOf (Var _ t) = t typeOf (Lam _ _ t) = t typeOf (App _ _ t) = t -data Env = Env {nextVar :: Int, typeEnv :: Map.Map Text Type} +data Context = Context {nextVar :: Int, typeContext :: Map.Map Text Type} deriving (Eq, Show) annotate :: Eval.Term -> Either TypeError (ATerm Type) annotate t = - evalStateT (go (fromTerm t) []) newEnv + evalStateT (go (fromTerm t) []) newContext where - go :: ATerm a -> [(Text, Type)] -> StateT Env (Either TypeError) (ATerm Type) + go :: ATerm a -> [(Text, Type)] -> StateT Context (Either TypeError) (ATerm Type) go t bounds = case t of Var x _ -> case List.lookup x bounds of Just ty -> pure $ Var x ty @@ -73,22 +73,22 @@ annotate t = App a b _ -> App <$> go a bounds <*> go b bounds <*> freshVar -newEnv :: Env -newEnv = Env 0 Map.empty +newContext :: Context +newContext = Context 0 Map.empty -bind :: Text -> Type -> StateT Env (Either TypeError) () +bind :: Text -> Type -> StateT Context (Either TypeError) () bind x ty = do - modify (\(Env n env) -> Env n (Map.insert x ty env)) + modify (\(Context n env) -> Context n (Map.insert x ty env)) -lookup :: Text -> StateT Env (Either TypeError) (Maybe Type) +lookup :: Text -> StateT Context (Either TypeError) (Maybe Type) lookup x = do - Env _ env <- get + Context _ env <- get pure $ Map.lookup x env -freshVar :: (Monad m) => StateT Env m Type +freshVar :: (Monad m) => StateT Context m Type freshVar = do - get >>= \(Env n _) -> - modify (\(Env n' env') -> Env (n' + 1) env') >> pure (TyVar $ nameOf n) + get >>= \(Context n _) -> + modify (\(Context n' env') -> Context (n' + 1) env') >> pure (TyVar $ nameOf n) where nameOf n | n < 26 = pack [chr (n + ord 'a')] |
