tags:

views:

205

answers:

2

In haskell it is posible to partially apply an infix function using sections, for instance given the infix function < (less than) one can partially apply any of the function's arguments: (5 <) , (< 5)

In other words, in haskell we have the following shorthand notation:

op :: a -> b -> c
(`op` y) === \x -> x `op` y
(x `op`) === \y -> x `op` y

Does F# have a similar concept?

+4  A: 

No, neither of those (apart from standard partial application like (=) x).


Whereas I like the succinctness of Seq.find ((=) x), things like Seq.filter ((<) 3) (or even Seq.map (flip (-) 1)) are simply awkward to read and should immediately be replaced by a lambda expression, imo.

Kha
Thanks for the prompt answer. It's just that coming from haskell where filter (< 5) [1..10] yields [1,2,3,4], it confuses me that in F# List.filter ((<) 5) [1..10] returns [6;7;8;9;10]!
primodemus
Then don't write that ;)
ephemient
Well, that's my definition of '(really) awkward' ;)
Kha
primodemus: `<` is an operator, so you can write it out like this `(<) 5 10` which means the same thing as `5 < 10`. Likewise, `List.filter ((<) 5)` means the same thing as `List.filter (fun x -> 5 < x)`. I can understand how easy it is to read the code as "filter list for items less than 5", but I wouldn't consider that a gotcha.
Juliet
+3  A: 

If you want to invent your own standards...

let lsection x f y -> f x y
let rsection f y x -> f x y

Then lsection 5 (<) === (5 <) and rsection (<) 5 === (< 5).

Though really, without language support, just put a lambda in there and it'll be clearer.

ephemient