F # If List.exists

This is a school assignment, but everything that I am going to publish is done only by me and me. Therefore, I only demand your help for a tiny step in my assignment, in 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] 

For what help is needed, the if statement is called, which checks whether the element y is a member of the list ys

at the moment I get an error: "This expression should have been of type '' a → bool 'but there is a type of' BOOL 'here"

can someone tell me what i am doing wrong?

+7
list exists if-statement f # elements
source share
1 answer

List.exists expects the first argument to be a function that will be checked on the element and return a boolean value. You want to check if there is an item in the list that you could write:

 if List.exists ((=) y) ys then 

or even:

 if List.contains y ys then 

after the suggestion of Panagiotis.

+8
source share

All Articles