(* Meta Properties of Mini-ML * Author: Adam Poswolsky *) use "typeInfer.d"; (* loads signature and some type inference functions, including "checkType" *) params = ; (* Execution of eval judgment *) fun executeEval : -> * = fn => (, ) | => let val (, ) = executeEval in (, ) end | => (case (executeEval ) of (, ) => let val (,) = executeEval in (, ) end | (, ) => let val (,) = executeEval in (, ) end) | => let val (, ) = executeEval val (, ) = executeEval in (, ) end | => let val (, ) = executeEval in (, ) end | => let val (, ) = executeEval in (, ) end | => (, ) | => let val (, ) = executeEval val (, ) = executeEval val (, ) = executeEval in (, ) end | => let val (, ) = executeEval val (, ) = executeEval in (, ) end | => let val (, ) = executeEval in (, ) end | => let val (, ) = executeEval in (, ) end; (* Value Soundness *) fun vs : -> = fn => | => @ (vs ) | => vs | => vs | => @ (vs ) @ (vs ) | => (case (vs ) of => ) | => (case (vs ) of => ) | => | => vs | => vs | => vs | => vs ; (* Type Preservation *) (* Order in mutual induction *) sig type> ord (s N)>; fun tpscheme : -> -> -> -> -> = fn => tps | => (* Q1 : {t} of (lam E1') (T t) * Q2 : of V2 T1 * P : ofscheme (T Targ) T1 T2 * D : eval (E1' V2) V *) tpscheme

and tps : -> -> -> = fn => | => @ (tps ) | => tps | => let val = tps in tps end | => let val = tps val = tps in end | => let val = tps in end | => let val = tps in end | => | => (* D1 : eval E1 (lam E1') * D2 : eval E2 V2 * D3 : eval (E1' V2) V * * P1 : of E1 T * P2 : of E2 T1 * P3 : ofscheme T T1 T2 *) let val = tps (* Q1 : of (lam E1') T *) val = tps (* Q2 : of V2 T1 *) in tpscheme end | => let val = tps in tps end | => tps | => tps | => (case {} tps

of {} => ); params = , , ; type world = -> * ; fun inferTypeW : world -> -> = fn W => let val G99 = {} let fun convW : world -> expEnv = fn W1 => (case (W1 ) of (, R) => ) in checkType (convW (W with .)) (fn => ) (fn G' => G') end fun getType : ({} tpEnv) -> = fn G => case {} normalize (G \t) of {} => | {} => in getType G99 end; fun getScheme' : tpEnv -> -> -> -> tpEnv = fn G => let val G2 = unifyTypes G val G3 = unifyTypes G2 in G3 end | G => let val Gextended = {} getScheme' (G with => ) in freeG Gextended end; fun getScheme : -> -> -> = fn => | => let val Gextended = {} getScheme' (fn => ) fun getType : ({} tpEnv) -> = fn G => case {} normalize (G \t) of {} => | {} => val = getType Gextended val

= getScheme in end; fun calcOf : world -> -> -> = fn W => let fun paramCase : world -> -> -> = fn W => (case (W ) of (, ) => ) in paramCase W end | W => (case {} calcOf (W with .) of {} => ) | W => | W => let val = calcOf W in end | W => let val = calcOf W val = calcOf W val = case ({}{} calcOf (W with => (, )) ) of {}{} => in end | W => let val = calcOf W val = calcOf W in end | W => let val = inferTypeW W val = calcOf W in end | W => let val = inferTypeW W val = calcOf W in end | W => (case ({}{} calcOf (W with => (, )) ) of {}{} => ) | W => let val = inferTypeW W val = calcOf W val = inferTypeW W val = calcOf W val

= getScheme in end | W => let val = inferTypeW W val = calcOf W val = case ({}{} calcOf (W with => (, )) ) of ({}{} ) => in end | W => let val = inferTypeW W val = calcOf W val = calcOf W in end | W => (case ({}{} calcOf (W with => (, )) ) of {}{} => ); fun infer : _ -> -> * = fn W => let val = inferTypeW W in (, calcOf W ) end; (* Put it all together... *) params = .; fun test : -> * * * * = fn => let val (, ) = executeEval val = vs val (, ) = infer (fn .) val = tps in (,,,,) end; val example = test ; val example2 = test ; val example3 = test ; val example4 = test ;