Question: Use these function definitions for the problems below: fun map (f,xs) = case xs of [] => [] | first::rest => (f first)::(map(f, rest)) fun

Use these function definitions for the problems below:

fun map (f,xs) =

case xs of

[] => []

| first::rest => (f first)::(map(f, rest))

fun filter (f,xs) =

case xs of

[] => []

| first::rest => if f first

then first::(filter (f, rest))

else filter (f, rest)

1. Write ML expressions that do the following:

1. Defines a datatype investment with two subtypes:

Stock - a tuple consisting of a symbol (string), price (int), shares (int) and date (int*int*int) of purchase

Cash - a tuple consisting of an amount (int) of money and date (int*int*int) of deposit

2. Defines a function valueOf that takes one investment as its argument and:

if the investment is a Stock, returns the value of price x shares

if the investment is Cash, returns the amount of money in cash

3. Binds a Stock investment with values ("AAPL", 100, 5, (2015, 5, 10)) to the variable appleStock 4. Binds a Cash investment with the value (200, (2014, 3, 7)) to the variable myCash

5. Binds the value ("GOOG", 70, 15, (2014, 8, 3)) to googleStock 6. Binds the value ("FB", 20, 8, (2015, 2, 9)) to facebookStock

7. Binds the value (IBM, 30, 10, (2010, 6, 20)) to ibmStock 8. Creates a list of all five investments (appleStock, ibmStock, googleStock, facebookStock and myCash) bound to investmentList 9. Uses the map function above to bind a list with the value of all the investments in investmentList to the variable ans

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!