mp4 - MP 4 User Defined Types CS 421 Fall 2007 Revision 1.3...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: MP 4 User Defined Types CS 421 Fall 2007 Revision 1.3 Assigned September 18, 2007 Due September 25, 2007, at 23:59pm Extension 48 hours (20% penalty) 1 Change Log 1.3 Corrected the ouput for Problem 9, and the type in the statement of Problem 6. 1.2 Added an extra-credit problem. 1.1 Missing problems made visible. Some typos fixed. 1.0 Initial Release. 2 Objectives and Background After completing this MP, you should better understand: record types the option datatype user-defined algebraic datatypes Warning: You may not use any library functions whatsoever on Probblems 4 and 5 of this MP, except for and @ . You may use library functions freely elsewhere in this problem set. 3 Problems 3.1 Records This section is intended to familiarize you with record types in Ocaml. For these exercises, you have been given in the module Mp4common the following record type: type person = { first_name : string; last_name : string; age : int; soc_sec : int } ;; (You need to have open Mp4common at the top of your mp4.ml file.) 1. (5 pts) Write a function get name : Mp4common.person -> string that returns a persons name in the format of their last name followed by a comma and a space followed by their first name. # let get_name p = ... val get_name : Mp4common.person -> string = <fun> # get_name {first_name = "John"; last_name = "Smith"; age = 21; soc_sec = 999999999};;- : string = "Smith, John" 1 2. (5 pts) Write a function marry p1 p2 that creates a pair of persons (p1, p2) with p1 having the same first name, age and social security number as p1 s, and similarly for p2 with respect to p2 , but where they now share that same last name being the hyphenated concatenation of the last name of p1 followed by the last name of p2 . # let marry p1 p2 = ... val marry : Mp4common.person -> Mp4common.person -> Mp4common.person * Mp4common.person = <fun> # marry {first_name = "Mary"; last_name = "Perlman"; age = 24; soc_sec = 111111111} {first_name = "Frank"; last_name = "Lantry"; age = 26; soc_sec = 222222222};;- : Mp4common.person * Mp4common.person = ({first_name = "Mary"; last_name = "Perlman-Lantry"; age = 24; soc_sec = 111111111}, {first_name = "Frank"; last_name = "Perlman-Lantry"; age = 26; soc_sec = 222222222}) 3.2 The option Datatype This section is intended to familiarize you with the option datatype....
View Full Document

This homework help was uploaded on 04/21/2008 for the course CS 421 taught by Professor Kamin during the Fall '08 term at University of Illinois at Urbana–Champaign.

Page1 / 5

mp4 - MP 4 User Defined Types CS 421 Fall 2007 Revision 1.3...

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