This lab requires an independent study of the ML language. You are encouraged to use any web tutorials and resources to learn ML beyond those in the book and provided by me (i.e. you will need to find them).Given the size of the class, I will not be able to debug your code for youPlease do not send panicked emails requesting I fix your bug for you.Allow yourself plenty of time, and use patience, perseverance, and the internet to debug your code.I will gladly answer clarifying questions about the goals and instructions of the Lab assignment. What this means is that if you come to my office hours or email me with questions concerning the following items or their derivatives, the provided stock answer applies. When it comes to these assignments, think of me more as your client/customer who is acquiring your product. Before coming to me with a question regarding the assignment, ask whetheryou would ask a client/customer that question.
Can you take a look at this code and tell me what Im doing wrong? No.Can you help me debug this program? No.Can you help me get XXX running on my computer? No.Can you tell me why my code isnt working? No.MLFor this lab, you will use ML. You may use any flavor of ML of your choice. I recommend the Standard New Jersey flavor for Linux and MacOS, and PolyML for Windows.Whats Already In the FileThe provided code in file ml_lab.sml has the following pieces of code (in order from top tobottom of the file):Lines 1 8: A Header Comment Block, fill this in with appropriate information, note that yourfirst and last name do not have angle brackets surrounding them.(***************************************************************** CSCI 305 ML Programming Lab** <firstname> <lastname>* <email-address>****************************************************************)Line 10: The place where I would suggest placing your code.(* Define your data type and functions here *)Lines 12 31: Some simple funtions to print the contents of Sets, note these will not work untilyou have defined the sets data type with the corresponding Set and Empty constructors.(* Simple function to stringify the contents of a Set of characters *)fun stringifyCharSet Empty = | printCharSet (Set(y, ys)) = Char.toString(y) ^ ^ stringifyCharSet(ys);(* Simple function to stringify the contents of a Set of ints *)fun stringifyIntSet Empty = | printIntSet (Set(w, ws)) = Int.toString(w) ^ ^ stringifyIntSet(ws);(* Simple function to stringify the contents of a Set of strings *)fun stringifyStringSet Empty = | printStringSet (Set(z, zs)) = z ^ ^ stringifyStringSet(zs);(* Simple function that prints a set of integers *)fun print_int x = print ({ ^ stringifyIntSet(x) ^ }
);(* Simple function that prints a set of strings *)fun print_str x = print ({ ^ stringifyStringSet(x) ^ }
);(* Simple function that prints a set of characters *)fun print_chr x = print ({ ^ stringifyCharSet(x) ^ }
);Lines 33 37: Some example code for the list2Set function, note this will not work until afteryou define the list2Set function.list2Set [1, 3, 2];list2Set [#a, #b, #c];list2Set [];list2Set [6, 2, 2];list2Set [x, y, z, x];Lines 39 58: The code from the lab questions, from which answers to questions 1, 5, 7, 9 and10 will come.(* Question 1 *)f [3, 1, 4, 1, 5, 9](* Question 5 *)val quest5 = isMember one (list2Set [1, 2, 3, 4]);print (
Question 5: ^ Bool.toString(quest5) ^
);(* Question 7 *)val quest7 = list2Set [it, was, the, best, of, times,, it, was, the,print
Question 7: ;print_str quest7;print
;(* Question 9 *)print
Question 9: ;print_str (union (list2Set [green, eggs, and]) (list2Set [ham]));(* Question 10 *)print
Question 10: ;print_str (intersect (list2Set [stewed, tomatoes, and, macaroni]) (list2Set [macaroniOther FilesAlong with the source code in ml_lab.sml there are three other files:LICENSE A simple license for this code based on the MIT License.README What you are currently reading.README.pdf A pdf version of what you are currently reading.WarmupBegin by entering this function in ML. The lines that begin with a semicolon are comment lines thatyou will fill in.fun f [] = [] (* a *)| f (x::xs) = (x + 1) :: (f xs) (* b *)Lab Questions 1 41. Run this function as f [3, 1, 4, 1, 5, 9] . What output do you get?2. What does this function f do?3. Give a comment that explains the line following (a) .4. Give a comment that explains the line following (b) .Sets datatypeConstruct a datatype used to represent sets, called set , it should have two different types: Setand Empty . Where Set is of type element * element set , meaning that it hold somepolymorphic type element and a sets of element .isMember functionWrite a function isMember that determines if an element e is part of the set, set . This functionwill return true if e is a member of the set, set , and false otherwise.fun isMember e set = ; (* complete this function definition *)list2Set functionWrite a function list2Set that convertes a list into a set ensuring that the properties of a wellformed set, i.e., that is has no duplicates, are maintained. You may find it useful to make use ofyour isMember function in your list2Set function.For example:list2Set [1, 3, 2]; => Set (1, Set (3, Set (2, Empty)))list2Set [#a, #b, #c]; => Set (#a, Set (#b, Set (#c, Empty)))list2Set []; => Emptylist2Set [6, 2, 2]; => Set (6, Set(2, Empty))list2Set [x, y, z, x]; => Set (x, Set (y, Set (z, Empty)))fun isSet set = ; (* complete this function definition *)Lab Questions 5 8Your answers must reflect the output of your code. No credit will be given to answers if you havenot submitted the respective correct function implementation.1. What output do you get for the call: isMember one [1, 2, 3, 4]2. Does your isMember function use head or tail recursion?3. What output do you get for the calllist2Set [it, was, the, best, of, times,, it, was, the, worst, of, times];1. Research tail recursion . Describe, in a few short sentences, why it can be beneficial towrite tail recursing functions.Union functionWrite a function union that takes the set union of set set1 and set set2 and returns a setrepresenting the mathematical union of the two sets. You may use the functions you definedpreviously ( list2Set and isMember ), if useful, in addition to any of the common ML functionsmentioned in class. Comment your function.fun union set1 set2 = ; (* complete this function definition *)Intersect functionWrite a function intersect that takes the set intersection of set set1 and set set2 and returnsa set representing the mathematical intersection of the two sets. Comment your function.fun intersect set1 set2 = ; (* Complete this function definition *)Lab Questions 9 10Your answers must reflect the output of your code for these functions. No credit will be given toanswers if you have not submitted the respective correct function implementation in ML.1. What output do you get for the call:union (list2Set [green, eggs, and]) (list2Set [ham]);1. What output do you get for the call:intersect (list2Set [stewed, tomatoes, and, macaroni]) (list2Set [macaroni,Lab Questions 11 15The following questions are for feedback and evaluation purposes. Points are awarded for anysincere answer.1. Name something you like about ML. Explain.2. Name something you dislike about ML. Explain.3. Did you enjoy this lab? Which aspects did you like and/or dislike?4. Approximately how many hours did you spend on this lab?5. Do you think you will use ML again? For which type(s) of project(s)?SubmissionEach student will complete and submit this assignment individually. Do not consult with others.However, you are encouraged to use the internet to learn ML but not to research thequestions asked in this lab.Comment your program appropriately.Save the final version of your program as [lastname]_[firstname].ml_lab.ml Type your labquestions in plain text as [lastname]_[firstname].ml_lab.questions.txt . Include your name inthe text file.Submit your files to the ML Lab dropbox folder on BrightSpace. Do not archive your files butinstead use two attachments. Submit your files before the due date as late submissions will not beaccepted.GradingTotal Assignment Points: 100, Total Grade Points: 7.5The rubric for this assignment is as follows:5 points each for questions 1 15, Total 75 pointsQuestions 1, 5, 7, 9, and 10 will be graded all or nothingQuestions 11 15, will be given full credit for reasonable answersThe remaining questions will be graded with partial credit15 points for working code, with no errors: All or nothing10 points for documented code2 points per function: isMember , list2Set , union , and intersect commented with agood description of what the function does2 points for header
Reviews
There are no reviews yet.