prac8-soln-spr10

# prac8-soln-spr10 - CMSC330 Spring 2010 Practice Problems 8...

This preview shows pages 1–3. Sign up to view the full content.

CMSC330 Spring 2010 Practice Problems 8 Solutions 1. Operational semantics Use operational semantics to determine the values of the following OCaml codes: a. 1 . . 1 1 b. + 3 7 3 3 7 7 + 3 7 10 c. + 1 ( + 2 3 ) 2 2 3 3 1 1 ( + 2 3 ) 5 + 1 ( + 2 3 ) 6 d. (fun x = 4 ) 5 • ; (fun x = 4) (• , λ x.4) // evaluate function to produce a closure • ; 5 5 // evaluate the argument // evaluate body of closure, after extending ( x: 5 ; 4 ) 4 // environment w/ binding for parameter) (fun x = 4) 5 4 e. (fun x = + x 6 ) 7 • ; (fun x = + x 6) (• , λ x.+ x 6) // evaluate function to produce a closure • ; 7 7 // evaluate the argument // evaluate body of closure, after extending ( x: 7 ; + x 6 ) 13 // environment w/ binding for parameter) • ; (fun x = + x 6) 7 13 f. (fun x = (fun y = + y x)) 8 9 • ; (fun x = (fun y = + y x)) (• , λ x.(fun y = + y x)) // eval func • ; 8 8 // eval arg x: 8 ; (fun y = + y x) ( x: 8, λ y.(+ y x)) // eval body • ; (fun x = (fun y = + y x)) 8 ( x: 8, λ y.(+ y x)) // eval func • ; 9 9 // eval arg x: 8 , y : 9 ; (+ y x) 17 // eval body • ; (fun x = (fun y = + y x)) 8 9 17

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2. Programming languages a. Describe the difference between ad-hoc and parametric polymorphism. Ad hoc polymorphism applies to code supporting a finite range of types whose combinations must be specified, parametric polymorphism applies to code written without mention to type that can transparently support
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 01/13/2012 for the course CMSC 330 taught by Professor Staff during the Fall '08 term at Maryland.

### Page1 / 4

prac8-soln-spr10 - CMSC330 Spring 2010 Practice Problems 8...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online