You could also, prioritize evaluation using parenthesis:

1
2
3
4
let x = 2 |> ((-) 3)
//or using partially applied function
let subTo3 = (-) 3 //val subTo3 : (int -> int)
let x = 2 |> subTo3
By on 10/11/2011 6:32 PM ()

Your solution still gives 1, instead of -1. That is because (-) a b translates into a - b.

So with your code:

1
let x = 2 |> ((-) 3)

This is equivalent:

1
let x = (-) 3 2 // id est: 3 - 2
By on 10/11/2011 7:01 PM ()

Oops, misreading of the question :/

By on 10/12/2011 4:41 PM ()

The problem is not the |> - Operator, but the function on the right of it. |> works with one argument so if you have a function f : 'a -> 'b then the operator is defined as "x |> f := f x (or f(x) if you like)". What you have on the right is curried function op : 'a -> 'b -> 'c and you provide it with one parameter ("3" in your case) to get the desired behaviour.

If you want to switch the parameters you can define a function swap and write

1
2
3
4
5
 

let swap f a b = f b a
let x = 2 |> (swap (-)) 3

(PS: with Haskells Sections you could more satisfyingly write (+ (-3)) instead of (swap (-)) 3 but sadly F# don't has all the nice syntactic sugar Haskell has (yet?))

By on 7/3/2011 9:21 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper