Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Implement a function that mimics built-in map function in SML. Apply foldr, foldl, and map to solve some problem with a single line of code.
Implement a function that mimics built-in map function in SML.
Apply foldr, foldl, and map to solve some problem with a single line of code.
2. Define a function named mymap2 with the same type and behavior as map, but unlike before you may not use foldr nor foldl. You still cannot use map itself either. (Refer to problem Exercise 26 on page 147.)
$ sml Standard ML of New Jersey (64-bit) v110.99 [built: Thu Dec 24 11:47:23 2020] - 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 - In: 'a list -> int val ordlist = fn ; char list -> int list val max - En ! int list -> int val it = () : unit - ordlist [#"A", "B", "C"); val it - [65,66,67] : int list - mylength 0; 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 $ sml Standard ML of New Jersey (64-bit) v110.99 [built: Thu Dec 24 11:47:23 2020] - 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 - In: 'a list -> int val ordlist = fn ; char list -> int list val max - En ! int list -> int val it = () : unit - ordlist [#"A", "B", "C"); val it - [65,66,67] : int list - mylength 0; 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
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