src/HOL/MiniML/W.thy
author nipkow
Wed, 25 Oct 1995 09:46:46 +0100
changeset 1300 c7a8f374339b
child 1376 92f83b9d17e1
permissions -rw-r--r--
New theory: type inference for let-free MiniML
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     1
(* Title:     HOL/MiniML/W.thy
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     2
   ID:        $Id$
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     3
   Author:    Dieter Nazareth and Tobias Nipkow
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     4
   Copyright  1995 TU Muenchen
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     5
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     6
Type inference algorithm W
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     7
*)
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     8
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     9
W = MiniML + 
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    10
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    11
types 
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    12
        result_W = "(subst * type_expr * nat)maybe"
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    13
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    14
(* type inference algorithm W *)
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    15
consts
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    16
	W :: "[expr, type_expr list, nat] => result_W"
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    17
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    18
primrec W expr
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    19
  W_Var	"W (Var i) a n = (if i < length a then Ok(id_subst, nth i a, n)
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    20
		          else Fail)"
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    21
  W_Abs	"W (Abs e) a n = W e ((TVar n)#a) (Suc n)    bind   
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    22
		         (%(s,t,m). Ok(s, Fun (s n) t, m) )"
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    23
  W_App	"W (App e1 e2) a n =
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    24
 		 W e1 a n    bind
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    25
		 (%(s1,t1,m1). W e2 ($ s1 a) m1   bind   
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    26
		 (%(s2,t2,m2). mgu ($ s2 t1) (Fun t2 (TVar m2)) bind
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    27
		 (%u. Ok( ($ u) o (($ s2) o s1), $ u (TVar m2), Suc m2) )))"
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    28
end