Question
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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started