I think I want it be be of type 'a list * 'a list -> 'a list .
intersection should return the intersection of two lists sample input and output:
- intersection ([1],[1]);
- [1]
- intersection ([1,2,3],[1,2]);
- [1,2]
- intersection ([[2,3],[1,2],[2,3]], [[1],[2,3]]);
- [[2,3]]
my function:
fun intersection (l1, l2) = let
fun intersection_acc (acc, [], h::t) = []
| intersection_acc (acc, h::t, []) = []
| intersection_acc (acc, h::t, h2::t2) = if in_list (h, l2)
then intersection_acc (h::acc, t, l2)
else intersection_acc (acc, t, l2)
in intersection_acc ([], l1, l2)
end
I don't think in_list is the problem, but that looks like this:
fun in_list (x, []) = false
| in_list (x, y::r) = if x = y
then true
else in_list (x, r);