Instructions: you will do this problem set by modifying the source file ps1.sml (which can be found in ps1.zip) and submitting the program that results. The program that you submit must compile. Programs that do not compile will receive an automatic zero. If you are having trouble getting your assigment to compile, please visit consulting hours. If you run out of time, it is better to comment out the parts that do not compile and hand in a file that compiles, rather than handing in a more complete file that does not compile.
Note: for functions that are not implemented, you should see something of the form "raise Fail "Not implemented."". You should remove this text and replace it with the body of the function.
We will test your code using an automated test script. Do not change variable names. Do not change function names. Do not remove our delimiters. Pay scrupulous attention to types. You have been warned.
There are five separate parts to this assignment.
Post a test message to cornell.test with the subject "CS312
Test".
DO NOT post test messages to the course newsgroup or you
may be penalized.
The following code is despondent about its appearence. Give it a makeover! While each function is technically correct, they are all very difficult to read. Fix the indentation, use let to avoid unnecessary expressions, or whatever else you feel is needed to fix any violations of the style guide.
Write val and fun declarations as follows:
The following functions will not compile. Please correct this without deleting or commenting out any code.
fun f():int = let val x = "Toast is good." in x end
(#"l",_)=>"lambda" (#"r",1)=>"recursion is #1 in my book!" (#"r",2)=>"recursion is second best only to parametric polymorphism!" (#"r",_)=>"I've got nothing" (#"L",_)=>"Lambda" (_,_) =>"unexpected character"Please note that the code you have been given looks ok, but does not follow cs312 style. This is intentional. While the optimal way to correct g would involve rewriting the case into proper style, do not do that here.
fun g(s:char, t:int):string = case s of #"l" => "lambda" | #"r" => case t of 1 => "recursion is #1 in my book!" | 2 => "recursion is the second best " ^ "only to parametic polymorphism!" | _ => "i've got nothing" | #"L" => "Lambda" | _ => "unexpected character"
The basis library is one of the most helpful resources you have on your quest to learn SML. For this part of the assignment, you should browse The Standard ML Basis Library and then write short (preferably one line) functions using the functions in the basis library.