Level 1 – Warm-up Component
The following functions should be placed in the warmup.ml file.
min list: ‘a list ->
Write a recursive unction that computes the minimal value in a list, using an option type to indicate it such a value was found or not
Copyright By PowCoder代写 加微信 powcoder
Some sample assert expressions to indicate the behavior of this function
assert (min list 2:3:1:4:5 = Some
assert (min
‘el = Some ‘a’):
assert (min list (1
longest_string_list: string list -> string option
Write a recursive function that finds the longest string in a list, using the option type to indicate if such a value is found or not
It two or more strinas have the longest enaths, return the first one.
Some samble assert expressions to indicate the behavior of this function
assert (longest_string_list [“Hello”; “Goodbye”; “Hi”] =
“Goodbye”);
assert (longest string list “Hi: “Hello”: “Be”: “Sorry”‘]
Some “Hello”)
sum tree: int tree -> int
Write a recursive function that adds up all the integers in an int tree. For this function, and several below, recall the definition of the
tree type:
a tree = Empty
of ‘a tree * a * ‘a tree
Some sample assert expressions to indicate the behavior of this function
assert (sum tree Emotv = 0):
assert (sum tree (Fork (Fork (Empty, 2, Empty)
Fork (Fork (Empty, 4, Empty),
Fork (Empty, 6, Empty)
max_tree: int tree -> int option
write a recursive unction tat computes in in tree , Using an option Ir sun valu wsTo TTOL.
Some sample assert expressions to indicate the behavior of this function
assert (max tree Empty = None):
assert (max tree (Fork (Fork (Emptv. 2. Emptv).
Fork (Fork (Emptv. 4. Emotv)
Fork (Empty, 6, Empty)
)) = Some 6);
assert (max tree (Fork (Fork (Emotv. 2. Emptv)
Fork (Fork (Empty, 4, Empty),
Fork (Empty, 6, Empty)
)) = Some 15)
max rose: int rose tree -> int
Write a recursive function that computes the maximal value in a ‘a rose tree. Since a rose tree has at least one value we do not
need to option tvoe tor this tunction.
For this function. and several below. recall the definition of the rose tree toe
a * a rose tree list
Some sample assert expressions to indicate the behavior of this function
assert (max_rose (Rose (4, I])) = 4);
assert max rose
(Rose (4, [ Rose (3,
Rose (b, I Rose
(Note that we have changed the spelling from rosetree to rose_tree .)
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com