U of I CS 421 - Exams (20 pages)

Previewing pages 1, 2, 19, 20 of 20 page document View the full content.
View Full Document

Exams



Previewing pages 1, 2, 19, 20 of actual document.

View the full content.
View Full Document
View Full Document

Exams

83 views

Problems/Exams


Pages:
20
School:
University of Illinois
Course:
Cs 421 - Natural Language Processing
Natural Language Processing Documents

Unformatted text preview:

1 Give the types of each of the following Ocaml functions a let alwaysfour x 4 val alwaysfour a int b let add x y x y val add int int int c let concat x y x y val concat string string string d let addmult x y x y x y val addmult int int int int e let rec f x if x then else hd x f tl x val f a list list a list f let rec copy x if x then else hd x copy tl x val copy a list a list g let b x y x y val b int int int h let c x y x val c a b a i let d x match x with a b a val d a b a j let e x hd x 1 val e int list int k let f x y match x with 0 a b a y val f int list int int l let g a b c d a d b c Recall that is the string concatenation operation val g int string string int int string m let rec h x match x with 0 a b r a h r val h int a list int 1 2 Define the following OCaml functions a contains a a list bool such that contains x lst returns true if and only if lst has x as one of its elements Do not use any pre existing functions E g contains 4 3 4 5 true let rec contains x lst match lst with false y ys x y contains x ys b evens a list a list returns the 2nd 4th etc elements of its argument E g evens 13 5 9 0 7 8 5 0 8 let rec evens lis match lis with a a b lis b evens lis c Implement the Ocaml function partition int list int list list which divides a list into runs of the same integer e g partition 9 9 5 6 6 6 3 9 9 5 6 6 6 3 You may define auxiliary functions but it is not actually necessary let rec partition lis if lis then else match partition tl lis with hd lis x xs if hd lis hd x then hd lis x xs else hd lis x xs d genlist m n m m 1 n or if m n let rec genlist m n if m n then else m genlist m 1 n 2 f compress int list int int list replaces runs of the same integer with a pair giving the count and the number E g compress 1 1 5 6 6 6 3 2 1 1 5 3 6 1 3 let rec compress lis if lis then else match compress tl lis with 1 hd lis n x lis if x hd lis then n 1 x lis else 1 hd



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view Exams and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Exams and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?