2

The type of this function is T -> (T -> U) -> U. I believe that in Haskell, it would be something like ($ . flip).

Or, from an object-oriented perspective (which is the way I've been looking at it):

type T {
    U myFunction(f: T -> U) {
        return f(this);
    }
}

I've been calling it "into" in my notes, and using a single arrow (->) as an operator. It's analogous to the map function, but for a scalar:

       a.into f =  f(a)
[a, b, c].map f = [f(a), f(b), f(c)]

Examples of practical applications:

42 -> Math.sqrt
foo.bar.into(doSomething).baz.into(doSomethingElse).xyzzy
(rather than doSomethingElse(doSomething(foo.bar).baz).xyzzy)
Thom Smith
  • 13,916
  • 6
  • 45
  • 91

1 Answers1

0

It looks like F# has this function. The function doesn't seem to be named, but the operators is known as the pipeline operator. http://msdn.microsoft.com/en-us/library/dd233229.aspx

let result = 100 |> function1 |> function2

In Haskell, it is flip id. A certain facetious package called data-aviary defines it as thrush. Is there an inverse of the Haskell $ operator?

Community
  • 1
  • 1
Thom Smith
  • 13,916
  • 6
  • 45
  • 91