quiz3-example-soln-fall11

quiz3-example-soln-fall11 - CMSC330 Fall 2011 Example Quiz...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CMSC330 Fall 2011 Example Quiz 3 Solutions 1. (16 pts) OCaml Types and Type Inference a. (2 pts each) Give the type of the following OCaml expressions i. [ (“1”, 2) ; (“3”, 4) ] Type = ( string * int ) list ii. fun f a -> [a ; a+1] Type = int -> int list b. (3 pts each) Write an OCaml expression with the following type i. int * int list Code = ( 2 , [2] ) ii. int list -> (int -> int) Code = let f a b = match a with (h::t) -> h+b c. (3 pts each) Give the value of the following OCaml expressions. If an error exists, describe the error. i. [1;2]::[3] Error = 3 has type int but is used with type int list OR [3] has type int list but is used with type int list list OR can only add int list [1;2] to int list list OR trying to add int list [1;2] to int list [3] ii. let x y = y 3 in x (fun z -> z – 1) Value = 2 2. (18 pts) OCaml Programming Solve the following OCaml programming problems. You are allowed to use List.rev (reverses a list) and the following (curried) map and fold functions, but no other OCaml
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
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 / 2

quiz3-example-soln-fall11 - CMSC330 Fall 2011 Example Quiz...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online