InutitionTC  0.30
Functions
typechecker.h File Reference

The core logic of the typechecker. More...

#include <string.h>
#include <stdbool.h>
#include "checker.h"
#include "envmap_base.h"

Go to the source code of this file.

Functions

KindinferType (const envmap env, Type *t)
 
TypeinferTerm (const envmap env, Term *m)
 
bool checkTerm (const envmap env, Term *m, Type *t)
 
bool checkType (const envmap env, Type *t, Kind *k)
 
bool checkKind (const envmap env, Kind k)
 

Detailed Description

The core logic of the typechecker.

Author
Marcin Benke
Aleksy Schubert
Maciej Zielenkiewicz

Function Documentation

bool checkKind ( const envmap  env,
Kind  k 
)

383 388 – | Check if a kind is well-formed wrt an environment checkKind :: MonadError String m => Env -> Kind -> m () checkKind env Kstar = return () checkKind env (Kpi n t k) = do env' <- insertMVar n t env checkKind env' k

bool checkTerm ( const envmap  env,
Term m,
Type t 
)

427 432 checkTerm env m t = do t' <- inferTerm env m if betaEq t t' then return () else reportError ["Actual type:",show t', "\nis not equal to expected:",show t]

bool checkType ( const envmap  env,
Type t,
Kind k 
)

390 398 – | Check if a type expression is of a specified kind – env |- t : k ? checkType :: MonadError String m => Env -> Type -> Kind -> m () checkType env t k = do k' <- inferType env t if betaEq k k' then return () else reportError ["Actual kind:",show k', "\nis not equal to expected:",show k]

Type* inferTerm ( const envmap  env,
Term m 
)

434 517 inferTerm :: MonadError String m => Env -> Term -> m Type inferTerm env (Mvar n) = lookupMvar env n inferTerm env (Mlam n t m) = do env' <- insertMVar n t env t' <- inferTerm env' m return (Tall n t t')

inferTerm env m@(Mapp m1 m2) = do tf <- inferTerm env m1 case tf of Tall n t1 t2 -> do checkTerm env m2 t1 catchError handler return $ substM n m2 t2 where handler e = reportError ["inferTerm ",show m,"\nWhen checking ", show m2,":",show t1,"\n",e, "\nEnv",unlines $ map show env]

t -> reportError [show t, "is not a function type"] – FIXME: better message

– [m1,m2]_{∃ x:phi1.phi2} inferTerm env (Mwit (Texi n t1 t2) m1 m2) = do checkTerm env m1 t1 checkTerm env (substM n m1 m2) (substM n m1 t2) return (Texi n t1 t2)

inferTerm env (Mwit t m1 m2) = reportError ["Witness for a nonexistential type"]

– abstract <n1:t1,n2:t2> = m1 in m2 inferTerm env m@(Mabs n1 t1 n2 t2 m1 m2) = do env' <- insertMVar n1 t1 env let t = (Texi n1 t1 t2) checkTerm env' m1 t catchError (h1 t) env'' <- insertMVar n2 t2 env' inferTerm env'' m2 catchError h2 where h1 t e = reportError ["inferTerm ",show m,"\nWhen checking ", show m1,":",show t,"\n",e] h2 e = reportError ["In ",show m,"\nIn ",show m2,"\n",e]

inferTerm env (Mtup t m1 m2) | (Tand t1 t2) <- nf t = do checkTerm env m1 t1 checkTerm env m2 t2 return t | otherwise = reportError ["Tuple not of and type"]

inferTerm env (Mpi1 m) = do t <- inferTerm env m case t of (Tand t1 t2) -> return t1 _ -> reportError [show t, "is not a pair type"]

inferTerm env (Mpi2 m) = do t <- inferTerm env m case t of (Tand t1 t2) -> return t2 _ -> reportError [show t, "is not a pair type"]

inferTerm env (Min1 t m) | Tor t1 t2 <- t = do checkTerm env m t1 return t | otherwise = reportError ["in1 into",show t,"which is not disjunction"]

inferTerm env (Min2 t m) | Tor t1 t2 <- t = do checkTerm env m t2 return t | otherwise = reportError ["in2 into",show t,"which is not disjunction"]

inferTerm env (Mcas m (n1,t1,m1) (n2,t2,m2)) = do checkTerm env m (Tor t1 t2) env1 <- insertMVar n1 t1 env t3 <- inferTerm env1 m1 env2 <- insertMVar n2 t2 env checkTerm env2 m2 t3 return t3

inferTerm env (Meps t m) = do checkTerm env m Tbot return t

Kind* inferType ( const envmap  env,
Type t 
)

402 422 – | Infer kind of a type expression – env |- t : ? inferType :: MonadError String m => Env -> Type -> m Kind inferType env (Tvar n) = lookupTvar env n inferType env (Tall "_" t1 t2) = inferType env t2 inferType env (Tall n t1 t2) = do env' <- insertMVar n t1 env inferType env' t2 inferType env (Tapp t m) = do k <- inferType env t case k of Kpi x t1 k1 -> do checkTerm env m t1 return $ substM x m k1 Kstar -> reportError ["checkType Tapp: expected product kind"] inferType env (Texi n t1 t2) = do env' <- insertMVar n t1 env inferType env' t2 inferType env (Tand t1 t2) = mapM_ (checkIsType env) [t1,t2] >> return Kstar inferType env (Tor t1 t2) = mapM_ (checkIsType env) [t1,t2] >> return Kstar inferType env Tbot = return Kstar