Sei sulla pagina 1di 1

CS 421 Quiz 8 Solution

1. Write down a rule for doing type inference for let expressions.
( exp1 ) = 1
( [ = 1] )
( ( exp1 ) ) = 2

2. Using your rule, derive types for the following expression or determine that no such type
exists.
Let p = proc (z) z in if p then 88 else 99

( 2 ) =
( 88 2 ) =
( () [ = ]0 ) =
( 99 2 ) =
( (() ) 1 ) = ( )
( ( 88 99) [ = ( )]1 )
( (let p = proc(z) z in if p then 88 else 99) 0 )

1 = [ = ]0
2 = [ = ( )]1
No type exists. You see that type of p is supposed to be bool but it is (tz -> tz) in tenv2
which is an error.

Potrebbero piacerti anche