# Haskell Filter Function
filt _ [] = []
filt f (x:xs)
| f x = x : filt f xs
| otherwise = filt f xs
main = do
let nums = [1..10]
let odds = filt odd [1..10]
print $ nums
print $ odds
# F# Filter Function
let rec filt f = function
| [] -> []
| x::xs when f x -> x :: filt f xs
| x::xs -> filt f xs
[<EntryPoint>]
let main argv =
let nums = [1..10]
let odds = filt odd [1..10]
printfn "%A" nums
printfn "%A" odds
0 // return an integer exit code
# Ocaml Filter Function
let rec filt f = function
| [] -> []
| x::xs when f x -> x :: filt f xs
| _::xs -> filt f xs
let () =
let nums = List.init 10 (fun x -> x + 1) in
let odds = filt (fun x -> x mod 2 <> 0) nums in
List.iter print_int nums;
List.iter print_int odds
To embed this project on your website, copy the following code and paste it into your website's HTML: