In this exercise, we implement the classic functions over lists.
-
Write a function
mem : int -> int list -> bool
such thatmem x l
is true if and only ifx
occurs inl
. -
Write a function
append : int list -> int list -> int list
such thatappend l1 l2
is the concatenation ofl1
andl2
. -
Write a function
combine : int list -> int list -> (int * int) list
such thatcombine l1 l2
is the list of pairs obtained by joining the elements ofl1 and l2
. This function assumes thatl1
andl2
have the same length. For instance,combine [1;2] [3;4] = [(1, 3); (2, 4)]
. -
Write a function
assoc : (string * int) list -> string -> int option
such thatassoc l k = Some x if (k, x)
is the first pair ofl
whose first component isk
. If no such pair exists,assoc l k = None
.
let rec mem x l =
"Replace this string with your implementation." ;;
let rec append l1 l2 =
"Replace this string with your implementation." ;;
let rec combine l1 l2 =
"Replace this string with your implementation." ;;
let rec assoc l k =
"Replace this string with your implementation." ;;