prac4-fall09

prac4-fall09 - CMSC 330, Fall 2009, Practice Problems 4 1....

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

View Full Document Right Arrow Icon
CMSC 330, Fall 2009, Practice Problems 4 1. OCaml and Functional Programming a. Define functional programming b. Define imperative programming c. Define higher-order functions d. Describe the relationship between type inference and static types e. Describe the properties of OCaml lists f. Describe the properties of OCaml tuples g. Define pattern variables in OCaml h. Describe the usage of “_” in OCaml i. Describe polymorphism j. Write a polymorphic OCaml function k. Describe variable binding l. Describe scope m. Describe lexical scoping n. Describe dynamic scoping o. Describe environment p. Describe closure q. Describe currying 2. OCaml Types & Type Inference Give the type of the following OCaml expressions: a. [] b. 1::[] c. 1::2::[] d. [1;2;3] e. [[1];[1]] f. (1) g. (1,”bar”) h. ([1,2], [“foo”,”bar”]) i. [(1,2,”foo”);(3,4,”bar”)] j. let f x = 1 k. let f (x) = x *. 3.14 l. let f (x,y) = x m. let f (x,y) = x+y n. let f (x,y) = (x,y) o. let f (x,y) = [x,y] p. let f x y = 1 q. let f x y = x*y r. let f x y = x::y s. let f x = match x with [] -> 1 t. let f x = match x with (y,z) -> y+z u. let f (x::_) = x v. let f (_::y) = y w. let f (x::y::_) = x+y
Background image of page 1

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

View Full DocumentRight Arrow Icon
x. let f = fun x -> x + 1 y. let rec x = fun y -> x y z. let rec f x = if (x = 0) then 1 else 1+f (x-1) aa. let f x y z = x+y+z in f 1 2 3 bb. let f x y z = x+y+z in f 1 2 cc. let f x y z = x+y+z in f dd. let rec f x = match x with [] -> 0 | (_::t) -> 1 + f t ee. let rec f x = match x with [] -> 0 | (h::t) -> h + f t ff. let rec f = function [] -> 0 | (h::t) -> h + (2*(f t)) gg. let rec func (f, l1, l2) = match l1 with [] -> [] | (h1::t1) -> match l2 with [] -> [f h1] |(h2::t2) -> [f h1; f h2] 3. OCaml Types & Type Inference Write an OCaml expression with the following types: a. int list b. int * int c. int -> int d. int * int -> int e. int -> int -> int f. int -> int list -> int list g. int list list -> int list h. ‘a -> ‘a i. ‘a * ‘b -> ‘a
Background image of page 2
Image of page 3
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 / 6

prac4-fall09 - CMSC 330, Fall 2009, Practice Problems 4 1....

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

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