This is a School Assignment but everything i am about to post is done by me and me only. Therefore I only require your help for a tiny step in my assignment at which i am stuck.
let rec removeDuplicates2 xs =
match xs with
|[]->[]
|y::ys -> if y = (List.exists y ys) then
(removeDuplicates2 ys)
else
y::(removeDuplicates2 ys)
printfn "%A" (removeDuplicates2 [3;1;3;2;1]) // result must be [3;1;2]
What i require help for is making the if statement that checks if element y is a member of list ys
at the moment i get the error saying: "This expression was expected to have type ''a -> bool' but here has type 'bool'"
can someone tell me what i am doing wrong?
List.exists expects the first argument to be a function which will be checked on the element and returns boolean value. You want to check if element is on the list you could write:
if List.exists ((=) y) ys then
or even:
if List.contains y ys then
following Panagiotis suggestion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With