I have been taking up F# recently (my background is C#) and am reading the site http://fsharpforfunandprofit.com, which I am finding very helpful.
I've got to http://fsharpforfunandprofit.com/posts/defining-functions/ which is the section on combinators. I understand them all (although the Y combinator or Sage bird screws with my mind!) with the exception of the Kestrel. Scott Wlaschin gives the definition (in F#) as:
let K x y = x
I can't understand for the life of me any situation in which this would be useful. At first I thought it might be used as chain operator, so that you can pass a value to a function and then get back the original value. I've written such an operator myself before, but as you can see it's not the same:
let (>|) x f = f x; x
If we partially apply the K combinator (with the value 5) then we get back a function that ignores its argument and instead returns 5. Again, not useful.
(K 5) = fun y -> 5
Can anyone give me an easy example of where this might be used please?
K
^^ – AnarchyK
is for example used to implement things like booleans, tuples, numbers, ... in the SKI calculuse (well it's a basic building block ;) ) - just think of it as a kind of projection to the first component – Anarchy