Theory TypeSystem
chapter ‹Generated by Lem from ‹semantics/typeSystem.lem›.›
theory "TypeSystem"
imports
Main
"HOL-Library.Datatype_Records"
"LEM.Lem_pervasives_extra"
"Lib"
"Namespace"
"Ast"
"SemanticPrimitives"
begin
function (sequential,domintros)
check_freevars :: " nat ⇒(string)list ⇒ t ⇒ bool " where
"
check_freevars dbmax tvs (Tvar tv) = (
Set.member tv (set tvs))"
|"
check_freevars dbmax tvs (Tapp ts tn) = (
((∀ x ∈ (set ts). (check_freevars dbmax tvs) x)))"
|"
check_freevars dbmax tvs (Tvar_db n) = ( n < dbmax )"
by pat_completeness auto
function (sequential,domintros)
type_subst :: "((string),(t))Map.map ⇒ t ⇒ t " where
"
type_subst s (Tvar tv) = (
(case s tv of
None => Tvar tv
| Some(t1) => t1
))"
|"
type_subst s (Tapp ts tn) = (
Tapp (List.map (type_subst s) ts) tn )"
|"
type_subst s (Tvar_db n) = ( Tvar_db n )"
by pat_completeness auto
function (sequential,domintros)
deBruijn_inc :: " nat ⇒ nat ⇒ t ⇒ t " where
"
deBruijn_inc skip n (Tvar tv) = ( Tvar tv )"
|"
deBruijn_inc skip n (Tvar_db m) = (
if m < skip then
Tvar_db m
else
Tvar_db (m + n))"
|"
deBruijn_inc skip n (Tapp ts tn) = ( Tapp (List.map (deBruijn_inc skip n) ts) tn )"
by pat_completeness auto
function (sequential,domintros)
deBruijn_subst :: " nat ⇒(t)list ⇒ t ⇒ t " where
"
deBruijn_subst skip ts (Tvar tv) = ( Tvar tv )"
|"
deBruijn_subst skip ts (Tvar_db n) = (
if ¬ (n < skip) ∧ (n < (List.length ts + skip)) then
List.nth ts (n - skip)
else if ¬ (n < skip) then
Tvar_db (n - List.length ts)
else
Tvar_db n )"
|"
deBruijn_subst skip ts (Tapp ts' tn) = (
Tapp (List.map (deBruijn_subst skip ts) ts') tn )"
by pat_completeness auto