i am trying to write a higher-order function pick, which picks elements that function f outputs as true and then output their values in list.
for example:
#let f a = if a>8 then true else false;;
pick [1;3;4;9;12;22] f;;
- : int list = [9;12;22]
i wrote this code so far but it doesn't work:
let rec pick f list =
let p1 = f list in
if (List.hd(p1)==true)
then List.hd(p1)::pick List.tl(p1)
else pick List.tl(p1)
Error: This expression has type 'a list but an expression was expected of type 'b -> bool#
How can i correct it so it will work on lists?