Reading: Webster Ch. 9
Write a function il2rl of type int list -> real list that takes a list of integers and returns a list of the same numbers converted to type real. For example, if you evaluate il2rl [1,2,3] you should get [1.0,2.0,3.0]
fun il2rl x = map real x;
Write a function band of type bool list -> bool that takes a list of boolean values and returns the logical AND of all of them. If the list is empty your function should return true
fun band x =
let
fun & (a, b) = a andalso b
in
foldr (op &) true x
end;
Write a function ordList of type char list -> int list that takes a list of characters and returns the list of the integer codes of those characters. For example, if you evaluate ordList [#"A", #"b", #"C"] you should get [65, 98, 67].
fun ordList x = map ord x;
Write a function sqsum of type int list -> int that takes a list of integers and returns the sum of the squares of those integers. For example, if you evaluate squm [1,2,3,4] you should get 30
fun sqsum x = foldr (op +) 0 (map (fn x => x * x) x);
Write a function append of type 'a list -> 'a list -> 'a list that takes two lists and returns the result of appending the second one onto the end of the first. For example, append [1,2,3] [4,5,6] should evaluate to [1,2,3,4,5,6]. Do not use the predefined appending utilities, like the @ operator or the concat function. Note that the function is curried.
fun append lst1 lst2 = foldr (op ::) lst2 lst1;
Write a function evens of type int list -> int list that takes a list of integers and returns the list of all the even elements from the original list (in the original order). For example, if you evaluate evens [1,2,3,4] you should get [2,4].
fun evens [] = []
| evens (x::xs) =
if x mod 2 = 0 then x::evens(xs)
else evens(xs);