Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**** In standard ML of New Jersey **** Objectives Implement a function that mimics built-in map function in SML. Apply foldr, foldl , and map

**** In standard ML of New Jersey ****

Objectives

Implement a function that mimics built-inmapfunction in SML.

Applyfoldr, foldl, andmapto solve some problems with a single line of code.

Problem description

Implement the following five functions:

1. Define a function namedmymap1with the same type and behavior as built-inmapfunction without actually usingmap. This should be one line of code and should usefoldrorfoldl. (Refer to problemExercise 24 on page 147.)

2. Define a function namedmymap2with the same type and behavior asmap, but unlike before you may not usefoldrnorfoldl. You still cannot usemapitself either. (Refer to problem Exercise 26 on page 147.)

3. Write a function namedordlistof type charlist -> int listthat takes a list of characters and returns the list of integer codes of those characters. For example, if you evaluateordlist[#A,#b, #C]you should get[65, 98, 67]. (Refer to Exercise 2 on page 144.)

4. Write a function namedmylengthof typea list -> intthat returns the length of a list. You can not use the built-inlengthfunction. (Refer to Exercise 11 on page 145.)

5. Write a function namedmaxof typeint list -> intthat returns the largest element of a list of integers. Your function must use eitherfoldrorfoldland need not behave well if the list is empty.

Sample run

$ sml

Standard ML of New Jersey (64-bit) v110.99 [built: Thu Dec 2411:47:232020]

- use "ProjectThree.sml";

[opening ProjectThree.sml]

val mymap = fn : ('a -> 'b) -> 'a list -> 'b list

val mymap2 = fn : ('a -> 'b) -> 'a list -> 'b list

val mylength = fn : 'a list -> int

val ordlist = fn : char list -> int list

val max = fn : int list -> int

val it = () : unit

- ordlist [#"A", #"B", #"C"];

val it = [65,66,67] : int list

- mylength [];

val it = 0 : int

- mylength [9, 1, 4, 2, 3, 8, 7];

val it = 7 : int

- max [8, 2, 5, 9, 4, 7, 1, 3];

val it = 9 : int

- max [~1,5,0];

val it = 5 : int

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

App Inventor

Authors: David Wolber, Hal Abelson

1st Edition

1449397484, 9781449397487

More Books

Students also viewed these Programming questions