Top Banner
Type Declarations Γ <num> : num [ ... <id>τ ... ] <id> : τ Γ true : bool Γ false : bool Γ e 1 : num Γ e 2 : num Γ {+ e 1 e 2 } : num Γ e 1 : bool Γ e 2 : τ 0 Γ e 3 : τ 0 Γ {if e 1 e 2 e 3 } : τ 0 Γ [ <id>τ 1 ] e : τ 0 Γ {fun {<id> : τ 1 } e} : (τ 1 τ 0 ) Γ e 0 : (τ 1 τ 0 ) Γ e 1 : τ 1 Γ {e 0 e 1 } : τ 0 1
62

Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Mar 17, 2018

Download

Documents

trancong
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Declarations

Γ <num> : num [ ... <id>←τ ... ] <id> : τ

Γ true : bool Γ false : bool

Γ e1 : num Γ e2 : num

Γ {+ e1 e2} : num

Γ e1 : bool Γ e2 : τ0 Γ e3 : τ0

Γ {if e1 e2 e3} : τ0

Γ[ <id>←τ1 ] e : τ0

Γ {fun {<id> : τ1} e} : (τ1 → τ0)

Γ e0 : (τ1 → τ0) Γ e1 : τ1

Γ {e0 e1} : τ0

1

Page 2: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference

Γ <num> : num [ ... <id>←τ ... ] <id> : τ

Γ true : bool Γ false : bool

Γ e1 : num Γ e2 : num

Γ {+ e1 e2} : num

Γ e1 : bool Γ e2 : τ0 Γ e3 : τ0

Γ {if e1 e2 e3} : τ0

Γ[ <id>←τ1 ] e : τ0

Γ {fun {<id>} e} : (τ1 → τ0)

Γ e0 : (τ1 → τ0) Γ e1 : τ1

Γ {e0 e1} : τ0

2

Page 3: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Do the rules still work? (Yes.)

[x ← num] x : num [x ← num] 1 : num

[x ← num] {+ x 1} : num

∅ ⊢ {fun {x} {+ x 1}} : (num -> num)

But how do we implement them now?

3

Page 4: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference

• Type inference is the process of inserting typeannotations where the programmer omits them

• We’ll use explicit question marks, to make it clearwhere types are omitted

{fun {x : ?} {+ x 1}}

4

Page 5: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference

• Type inference is the process of inserting typeannotations where the programmer omits them

• We’ll use explicit question marks, to make it clearwhere types are omitted

{fun {x : ?} {+ x 1}}

<typeExpr> ::= num| bool| (<typeExpr> -> <typeExpr>)| ?

5

Page 6: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference

{+ x 1}{fun {x : ?} }

6

Page 7: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference

{+ x 1}{fun {x : ?} }

T1

7

Page 8: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference

{+ x 1}{fun {x : ?} }

T1 num

8

Page 9: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference

{+ x 1}{fun {x : ?} }

T1 num

num T1 = num

9

Page 10: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference

{+ x 1}{fun {x : ?} }

T1 num

num T1 = num

(num → num)

10

Page 11: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference

{+ x 1}{fun {x : ?} }

T1 num

num T1 = num

(num → num)

• Create a new type variable for each ?

• Change type comparison to install type equivalences

11

Page 12: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference

{+ x 1}{fun {x : ?} }

T1 num

num T1 = num

(num → num)

{if true 1 x}{fun {x : ?} }

12

Page 13: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference

{+ x 1}{fun {x : ?} }

T1 num

num T1 = num

(num → num)

{if true 1 x}{fun {x : ?} }

bool

13

Page 14: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference

{+ x 1}{fun {x : ?} }

T1 num

num T1 = num

(num → num)

{if true 1 x}{fun {x : ?} }

bool int

14

Page 15: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference

{+ x 1}{fun {x : ?} }

T1 num

num T1 = num

(num → num)

{if true 1 x}{fun {x : ?} }

bool int T1

15

Page 16: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference

{+ x 1}{fun {x : ?} }

T1 num

num T1 = num

(num → num)

{if true 1 x}{fun {x : ?} }

bool int T1

num T1 = num

16

Page 17: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference

{+ x 1}{fun {x : ?} }

T1 num

num T1 = num

(num → num)

{if true 1 x}{fun {x : ?} }

bool int T1

num T1 = num

(num → num)

17

Page 18: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Impossible Cases

{if x 1 x}{fun {x : ?} }

18

Page 19: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Impossible Cases

{if x 1 x}{fun {x : ?} }

T1

19

Page 20: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Impossible Cases

{if x 1 x}{fun {x : ?} }

T1 num

20

Page 21: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Impossible Cases

{if x 1 x}{fun {x : ?} }

T1 num T1

21

Page 22: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Impossible Cases

{if x 1 x}{fun {x : ?} }

T1 num T1

no type: T1 can't be both bool and num

22

Page 23: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Many Cases

{fun {y : ?} y}

23

Page 24: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Many Cases

{fun {y : ?} y}

T1

24

Page 25: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Many Cases

{fun {y : ?} y}

T1

(T1 → T1)

25

Page 26: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Many Cases

{fun {y : ?} y}

T1

(T1 → T1)

• Sometimes, more than one type works

(num → num)

(bool → bool)

((num → bool) → (num → bool))

so the type checker leaves variables in the reportedtype

26

Page 27: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Function Calls

{{fun {y : ?} y} {fun {x : ?} {+ x 1}}}

27

Page 28: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Function Calls

{{fun {y : ?} y} {fun {x : ?} {+ x 1}}}

(T1 → T1)

28

Page 29: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Function Calls

{{fun {y : ?} y} {fun {x : ?} {+ x 1}}}

(T1 → T1) (num → num)

29

Page 30: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Function Calls

{{fun {y : ?} y} {fun {x : ?} {+ x 1}}}

(T1 → T1) (num → num)

T1 = (num → num)

30

Page 31: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Function Calls

{{fun {y : ?} y} {fun {x : ?} {+ x 1}}}

(T1 → T1) (num → num)

(num → num)T1 = (num → num)

31

Page 32: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Function Calls

{y 7}{fun {y : ?} }

32

Page 33: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Function Calls

{y 7}{fun {y : ?} }

T1

33

Page 34: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Function Calls

{y 7}{fun {y : ?} }

T1 num

34

Page 35: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Function Calls

{y 7}{fun {y : ?} }

T1 num

T2 T1 = (num → T2)

35

Page 36: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Function Calls

{y 7}{fun {y : ?} }

T1 num

T2 T1 = (num → T2)

((num → T2) → T2)

36

Page 37: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Function Calls

{y 7}{fun {y : ?} }

T1 num

T2 T1 = (num → T2)

((num → T2) → T2)

• In general, create a new type variable record for theresult of a function call

37

Page 38: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Cyclic Equations

{x x}{fun {x : ?} }

38

Page 39: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Cyclic Equations

{x x}{fun {x : ?} }

T1

39

Page 40: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Cyclic Equations

{x x}{fun {x : ?} }

T1 T1

40

Page 41: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Cyclic Equations

{x x}{fun {x : ?} }

T1 T1

no type: T1 can't be (T1 → ...)

• T1 can’t be int

• T1 can’t be bool

• Suppose T1 is (T2 → T3)

T2 must be T1

So we won’t get anywhere!

41

Page 42: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Inference: Cyclic Equations

{x x}{fun {x : ?} }

T1 T1

no type: T1 can't be (T1 → ...)

The occurs check:

• When installing a type equivalence, make sure that thenew type for T doesn’t already contain T

42

Page 43: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Unification

Unify a type variable T with a type τ2:• If T is set to τ1, unify τ1 and τ2

• If τ2 is already equivalent to T, succeed• If τ2 contains T, then fail• Otherwise, set T to τ2 and succeed

Unify a type τ1 to type τ2:• If τ2 is a type variable T, then unify T and τ1

• If τ1 and τ2 are both num or bool, succeed• If τ1 is (τ3 → τ4) and τ2 is (τ5 → τ6), then

unify τ3 with τ5

unify τ4 with τ6

• Otherwise, fail

43

Page 44: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

TIFAE Grammar

<TIFAE> ::= <num>| {+ <TIFAE> <TIFAE>}| {- <TIFAE> <TIFAE>}| <id>| {fun {<id> : <TE>} <TIFAE>}| {<TIFAE> <TIFAE>}| {if0 <TIFAE> <TIFAE> <TIFAE>}| {rec {<id> : <TE> <TIFAE>} <TIFAE>}

<TE> ::= num| (<TE> -> <TE>)| ? NEW

44

Page 45: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Representing Expressions

(define-type TFAE [num (n : number)] [add (l : TFAE)

(r : TFAE)] [sub (l : TFAE)

(r : TFAE)] [id (name : symbol)] [fun (name : symbol)

(t : TE) ; different(body : TFAE)]

[app (rator : TFAE)(rand : TFAE)])

45

Page 46: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Representing Type Variables

(define-type Type [numT] [boolT] [arrowT (arg : Type)

(result : Type)] [varT (is : (boxof MaybeType))])

(define-type TE [numTE] [boolTE] [arrowTE

(arg : TE)(result : TE)]

[guessTE])

(define-type MaybeType [none] [some (t : Type)])

46

Page 47: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Parsing Types

(define parse-type : (TE -> Type) (lambda (te)

(type-case TE te [numTE () (numT)] [boolTE () (boolT)] [arrowTE (d r)

(arrowT (parse-type d)(parse-type r))]

[guessTE () (varT (box (none)))])))

47

Page 48: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Unification

(define unify! : (Type Type -> ()) (lambda (t1 t2)

(type-case Type t1 [varT (b) (type-case MaybeType (unbox b)

[some (t1-2) (unify! t1-2 t2)] [none ()

(type-case Type t2 [varT (b2)

(type-case MaybeType (unbox b2) [some (t2-2) (unify! t1 t2-2)] [none () (if (eq? b b2)

(values)(begin (set-box!

b(some t2))

(values)))])] [else ...])])]

[numT () ...] [boolT () ...] [arrowT (d1 r1) ...])))

48

Page 49: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Unification

(define unify! : (Type Type -> ()) (lambda (t1 t2)

(type-case Type t1 [varT (b) (type-case MaybeType (unbox b)

[some (t1-2) (unify! t1-2 t2)] [none ()

(type-case Type t2 [varT (b2)

...] [else (if (occurs? b t2)

(error 'type-check "failed")(begin (set-box! b (some t2)) (values)))])])]

[numT () ...] [boolT () ...] [arrowT (d1 r1) ...])))

49

Page 50: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Type Unification

(define unify! : (Type Type -> ()) (lambda (t1 t2)

(type-case Type t1 [varT (b) ...] [numT () (type-case Type t2

[varT (b) (unify! t2 t1)] [numT () (values)] [else (error 'type-check "failed")])]

[boolT () (type-case Type t2 [varT (b) (unify! t2 t1)] [boolT () (values)] [else (error 'type-check "failed")])]

[arrowT (d1 r1) (type-case Type t2 [varT (b) (unify! t2 t1)] [arrowT (d2 r2)

(begin (unify! d1 d2)(unify! r1 r2))]

[else (error 'type-check "failed")])])))

50

Page 51: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

Occurs Check

(define occurs? : ((boxof MaybeType) Type -> boolean) (lambda (b t)

(type-case Type t [varT (b2) (or (eq? b b2)

(type-case MaybeType (unbox b2) [none () false] [some (t2-2) (occurs? b t2-2)]))]

[numT () false] [arrowT (d r) (or (occurs? b d)

(occurs? b r))])))

51

Page 52: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

TIFAE Type Checker

(define typecheck : (FAE TypeEnv -> Type) (lambda (fae env)

(type-case FAE fae ... [num (n) (numT)] ...)))

52

Page 53: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

TIFAE Type Checker

(define typecheck : (FAE TypeEnv -> Type) (lambda (fae env)

(type-case FAE fae ... [add (l r)

... (typecheck l env) ...

... (typecheck r env) ...] ...)))

53

Page 54: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

TIFAE Type Checker

(define typecheck : (FAE TypeEnv -> Type) (lambda (fae env)

(type-case FAE fae ... [add (l r) (begin

(unify! (typecheck l env) (numT) l) (unify! (typecheck r env) (numT) r) (numT))]

...)))

54

Page 55: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

TIFAE Type Checker

(define typecheck : (FAE TypeEnv -> Type) (lambda (fae env)

(type-case FAE fae ... [id (name) (get-type name env)]

[fun (name te body)(local [(define arg-type (parse-type te))] (arrowT arg-type

(typecheck body (aBind namearg-typeenv))))]

...)))

55

Page 56: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

TIFAE Type Checker

(define typecheck : (FAE TypeEnv -> Type) (lambda (fae env)

(type-case FAE fae ... [app (fn arg)

... (typecheck fn env) ...

... (typecheck arg env) ...] ...)))

56

Page 57: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

TIFAE Type Checker

(define typecheck : (FAE TypeEnv -> Type) (lambda (fae env)

(type-case FAE fae ... [app (fn arg)

(local [(define result-type (varT (box (none))))] ... (arrowT (typecheck arg env)

result-type) ... (typecheck fn env) ...)]

...)))

57

Page 58: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

TIFAE Type Checker

(define typecheck : (FAE TypeEnv -> Type) (lambda (fae env)

(type-case FAE fae ... [app (fn arg)

(local [(define result-type (varT (box (none))))] (begin

(unify! (arrowT (typecheck arg env)result-type)

(typecheck fn env)fn)

result-type))] ...)))

58

Page 59: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

TIFAE Type Checker

(define typecheck : (FAE TypeEnv -> Type) (lambda (fae env)

(type-case FAE fae ... [if0 (test-expr then-expr else-expr)

... (typecheck test-expr env) ...

... (typecheck then-expr env) ...

... (typecheck else-expr env) ...] ...)))

59

Page 60: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

TIFAE Type Checker

(define typecheck : (FAE TypeEnv -> Type) (lambda (fae env)

(type-case FAE fae ... [if0 (test-expr then-expr else-expr)

(begin (unify! (typecheck test-expr env) (numT) test-expr) ... (typecheck then-expr env) ... ... (typecheck else-expr env) ...)]

...)))

60

Page 61: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

TIFAE Type Checker

(define typecheck : (FAE TypeEnv -> Type) (lambda (fae env)

(type-case FAE fae ... [if0 (test-expr then-expr else-expr)

(begin (unify! (typecheck test-expr env) (numT) test-expr) (local [(define test-ty

(typecheck then-expr env))] (begin

(unify! test-ty(typecheck else-expr env)else-expr)

test-ty)))] ...)))

61

Page 62: Type Declarations - ece.northwestern.edurobby/courses/321-2014-winter/lecture1…Type Inference • Type inference is the process of inserting type annotations where the programmer

TIFAE Type Checker

(define typecheck : (FAE TypeEnv -> Type) (lambda (fae env)

(type-case FAE fae ... [rec (name ty rhs-expr body-expr)

(local [(define rhs-ty (parse-type ty))(define new-ds (aBind name

rhs-tyenv))]

(begin (unify! rhs-ty (typecheck rhs-expr new-ds) rhs-expr) (typecheck body-expr new-ds)))]

...)))

62