this is just a question regarding notation in OCaml.
I am trying to test the function
let rec add (x : 'a) (l : 'a set) : bool =
begin
match l with
| [] -> []
| hd :: rest ->
if x = hd then rest
else (hd :: (add x rest))
end
my test case is
let test () : bool =
add (3 [1; 2; 4]) = [1; 2; 3; 4]
;; run_test "add 3 [1; 2; 4]" test
I am getting an "this expression is not a function, cannot be applied" error
Is something wrong with my notation?
OCaml doesn’t have a built-in set type (instead there is a Set module, or library). So, there’s also no built-in notation for set constants.
For smallish sets, one often uses lists. And, in fact,
List.memis a function that operates on lists (not sets). The notation for a list is like this:[1; 2; 3; 4].(As a side comment, your function named
adddoesn’t add anything. But maybe you’re just getting started.)