due 11/22/99
Try these before section.
Suppose that the following Miranda script has been filed in:
cube x = x*x*x my_map f [] = [] my_map f (x:xs) = f x : my_map f xs my_append [] x = x my_append (x:xs) ys = x : my_append xs ys my_map2 f [] [] = [] my_map2 f (a:as) (b:bs) = f a b : my_map2 f as bs rev f x y = f y x alligator x y = 3+y
What is the result of evaluating the following Miranda expressions? (If there is a compile-time type error, or a run-time error, or a non-terminating computation, say so.) If the expression is followed by :: then give the type, instead of the value.
cube 3 | |
cube :: | |
my_map :: | |
my_map cube :: | |
my_map cube [1..] | |
my_append :: | |
my_map2 alligator [1..] [10..] | |
my_map2 :: | |
my_map2 alligator :: | |
my_map2 (rev alligator) :: | |
alligator (1/0) (6/2) | |
alligator (6/2) (1/0) | |
alligator :: | |
(rev alligator) 10 20 | |
rev :: | |
rev my_map2:: |
These are some sample problems that we will be discussing in section.
midpoint (2,0) (8,2) => (5.0,1.0) midpoint (-5,1) (5,-1) => (0.0,0.0)
no_duplicates [1, 3, 3, 8, 5, 3, 5] => [1, 3, 8, 5] no_duplicates [1, 3, 5] => [1, 3, 5] no_duplicates [] => []
Complete the following. You do not have to handle errors in input gracefully. As usual, you must turn in output of your code on a demonstrative set of test cases.
is_closer_than (2, 0) (8, 2) => True is_closer_than (-5, 1) (5, -1) => False
partition_points (3, 0) [(1, 0), (3, 0), (4, 0)] => ([(1,0)], [(3,0) (4 0)])
quicksort_points [(3, 0), (2, 0), (-4, 0), (1, 0)] => [(1, 0), (2, 0), (3, 0), (-4, 0)]
take 8 (gen_strings ['a','b']) => ["","a","b","aa","ab","ba","bb","aaa"]