(40 points) In this problem you are going to define an ML
datatype for boolean expressions. Boolean expressions are made
up of boolean values, boolean variables, and operators.
There are two boolean values, i.e., true or false.
A boolean variable (e.g., "p") is one which can taken on any of
the two boolean values.
Boolean expressions are constructed from boolean variables and values
using the operators AND, OR, and NOT (with their obvious meanings).
An example of a boolean expression is AND(OR(p,q), NOT(q)), where p
and q are boolean variables. Another is AND(p, true). Do the
following:
- Devise an ML datatype (see lecture summaries from Oct 10) called
boolexp whose
values
represent legal boolean expressions. You may assume that boolean
variables (but not the expressions themselves) are represented as strings.
- Write a function eval(E,L) that takes a boolean expression E
and a list of true boolean variables L, and determines the truth value
of E on the assumption that the boolean variables in L are true and all
other boolean variables are false.
For instance, if E represents AND(OR(p,q), NOT(q)) and L
is the list [p], then the result of eval(E,L) must be
true. Please keep in mind that E is not a string but a value
constructed from the boolexp datatype.
You may assume the following ML list member function is
available to you (and need not include its definition in your answer).
fun member (x, nil) = false
| member (x, y::ys) = x = y orelse member (x, ys);
This problem can be completed with at most one datatype definition
and one short (5 line) ML eval function.
Anything more elaborate will be given zero points.