Question: Problems In this lab, you will write recursive functions. !!! DO NOT USE LOOPS, MUTABLE VARIABLES, PATTERN MATCHING OR ANY LIBRARY FUNCTIONS. ONLY RECURSION IS

Problems

In this lab, you will write recursive functions.

!!! DO NOT USE LOOPS, MUTABLE VARIABLES, PATTERN MATCHING OR ANY LIBRARY FUNCTIONS. ONLY RECURSION IS ALLOWED !!!

  • Allowed library functions: List.head, List.tail, List.isEmpty

Problem 1

Write a recursive function prod: (lst:int list) -> int that returns a product of the elements in the integer list.

Problem 2

Write a recursive function map: (f:(int -> 'a) -> int list -> 'a list) that returns a new list whose elements are the results of applying the given function f to each of the elements of the integer list.

Problem 3

Write a recursive function odd: int list -> int list that returns a new list containing only odd elements of the original integer list.

Problem 4

Write a recursive function filter: (f:(int -> bool) -> int list -> int list) that returns a new list containing only the elements of the list for which the given predicate function f returns true.

module Assignment

// Problem 1

let rec prod (lst:int list) =

// write your solution here

0

// Problem 2

let rec map f (lst:int list) =

// write your solution here

[]

// Problem 3

let rec odd (lst:int list) =

// write your solution here

lst

// Problem 4

let rec filter f lst =

// write your solution here

lst

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!