What you've got is correct for finding even numbers. The only thing missing is that you need to call your evens
function, passing it list1
, like this: evens list1
.
Keep in mind that the parameters of a function are different from its arguments. In this case, you've called both the parameter and the argument list1
, which may be confusing you.
Here's a complete version, using two different names for clarity:
let myList = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10]
let evens anyList =
let isEven x = x % 2 = 0
List.filter isEven anyList
printfn "%A" (evens myList)
Once you understand how this works, you can try solving the full problem you mentioned.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…