Question: *****In SML/NJ****** 1. Write a function count_list with type int list -> int that returns the number of items in a list. An item that

*****In SML/NJ******

1. Write a function count_list with type

int list -> int

that returns the number of items in a list. An item that is repeated is counted each time it appears in the list.

2. Write an ML function sum_list with type

int list -> int

that returns the sum of all the elements within a list

3. Write a function countdown with the type

int -> int list

that returns a list of numbers from its argument down to 1.

countdown (5) = [5, 4, 3, 2, 1] countdown (10) = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

4. Write a function countup with type

int * int -> int list

that takes two arguments (start and finish) and returns a list with all the numbers between start and finish.

countup (1, 10) = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

countup (2, 7) = [2, 3, 4, 5, 6, 7]

5. Write a function find_last with type

int list -> int

that returns the last element in a list:

findlast [1, 3, 5, 7, 9] = 9

findlast [2, 3, 4, 5] = 5

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!