HW 5
Functional Programming and SML
Instructions:
- Due date: 12/14/2018
- Questions must be done in order.
- All SML code must be written and tested.
- Code with syntax errors will be graded as 0.
- The
presentation of the hard copy of your homework assignment must contain a
cover page with the homework number and your name, as well as the
current date and the due date. - The hard copy must contain the questions and your answers.
- You will provide screenshots to show that you tested your code.
- In case of problems with this homework, contact me by email at: v.mullick@me.com or text me at: 631-875-1890
Problem 1: FindBug
Use FindBug on the scanner and parser code you wrote and provide the results in a readable way.
http://findbugs.sourceforge.net
Problem 2: Types
- What are the types of the following expressions?
- [(1,5), (2,3), (5,6)];
- fun f(x:real) = true;
- map f;
- Provide expressions of the following types:
- int * bool
- int list * bool
- int * real -> bool list
Problem 3: Factorial and Fibonacci
Write the factorial and fibonnaci functions using exceptions in SML.
Provide the SML code. Show evidence of testing of your functions.
Problem 4: Evaluation of Functions
Problem 5: map
What is the type of map?
Use map to multiply by 3 each element of a list of ints.
Problem 6: insertOne
Write
a function that inserts 1 in front of each element of a list. It also
adds 1 at the beginning of the list. For example, insertOne[5,3,4]
returns [1,5,1,3,1,4]. insertOne[] returns [].
Provide the SML code. Show evidence of testing of your function.
Problem 7: SML Datatypes
This is a datatype describing the tree data structure.
datatype ‘a Tree = Empty | Node of āa * ‘a tree * ‘a tree; Using
the tree datatype construct the binary tree below.
Problem 8: Prolog
- Let us consider the following set of facts that describe the mother predicate.
mother(linda, paul).
mother(cathy, andrew).
The post Define a predicate female(X) which holds iff X is a female.. appeared first on WriteDen.
Source: my posts