4 ms·
# Rust let double = |x| 2 * x; double(3); // F# let double = (*) 2 double 3 -- Haskell let double = (*2) double 3
by itishappy 2y ago
# Rust
let double = |x| 2 * x;
double(3);
// F#
let double = (*) 2
double 3
-- Haskell
let double = (*2)
double 3
# Python
double = lambda x: 2 * x
double(3)
- bmitc 2y agoIf I am understanding that |x| 2 * x in Rust is an anonymous function, another F# equivalent is fun x -> 2 * x.
- neonsunset 2y agoThe Haskell and F# examples above use partial application. This also works: let zeroCount = numbers |> Seq.filter ((=) 0) |> Seq.length
- steveklabnik 2y agoIt's a closure, not just an anonymous function, though it of course has an empty environment so it's not a significant difference in this case. Rust doesn't have syntax for anonymous functions, only closures.
- deleted 2y ago[deleted]