Question: Can you please help me to create test problems ( at least 3 options for each question ) to ensure that my ML code is

Can you please help me to create test problems (at least 3 options for each question) to ensure that my ML code is working properly?
(* Question 1- Define a function mymap with the same type and behavior as map, but without using map.
(Note this should still be a one-liner: use foldl or foldr.)*)
fun mymap1 f lst=foldr (fn(x, acc)=>(f x) :: acc)[]lst;
(*val mymap1= fn : ('a ->'b)-> 'a list ->'b list*)
(* Question 2- Define a function mymap2 with the same type and behavior as map. No map,
foldr, or foldl can be used.(refer to problem Exercise 26on page 147)*)
fun mymap2 f lst = if null lst then [] else f (hd lst)::mymap2 f(tl lst);
(*val mymap2= fn : ('a ->'b)-> 'a list ->'b list*)
(* Question 3- Write a function ordlist of type char list -> int list that take a list of characters
and returns the list of integer codes of those characters.For example,if you
evaluate ordlist [#A,#b,#C]you should get [65,98,67](refer to
Exercise 2on page 144).*)
fun ordlist lst = map (fn c => ord c) lst;
(*val ordlist = fn : char list -> int list*)
(* Question 4- Write a function mylength fo type a list -> int that returns the length of a list.
You cannot use the built-in length function.(refer to Exercise 11on page
145).*)
fun mylength []=0| mylength (_::rest)=1+mylength rest;
(* val mylength = fn : 'a list -> int *)
(* Question 5- Write a function max of type int list -> int that returns the largest element of
a list of integers.Your function need not behave well if the list is empty.*)
fun max[]= raise Empty | max[x]=x | max(x::xs)= if x>max xs then x else max xs;
(* val max = fn : int list -> int *)

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 Programming Questions!