【问题标题】:Is there a common name for the function f(a b) = b(a)?函数 f(a b) = b(a) 有通用名称吗?
【发布时间】:2012-06-26 20:42:48
【问题描述】:

这个函数的类型是T -> (T -> U) -> U。我相信在 Haskell 中,它会类似于 ($ . flip)

或者,从面向对象的角度来看(这是我一直在看待它的方式):

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

我在笔记中将其称为“into”,并使用单个箭头 (->) 作为运算符。它类似于map 函数,但对于标量:

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

实际应用示例:

42 -> Math.sqrt
foo.bar.into(doSomething).baz.into(doSomethingElse).xyzzy
(rather than doSomethingElse(doSomething(foo.bar).baz).xyzzy)

【问题讨论】:

    标签: function terminology


    【解决方案1】:

    F# 好像有这个功能。该函数似乎没有命名,但操作符被称为管道操作符。 http://msdn.microsoft.com/en-us/library/dd233229.aspx

    let result = 100 |> function1 |> function2
    

    在 Haskell 中,它是 flip id。一个名为 data-aviary 的滑稽包将其定义为thrushIs there an inverse of the Haskell $ operator?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-25
      • 2012-03-18
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 2021-11-10
      • 1970-01-01
      相关资源
      最近更新 更多