2012-06-25 3 views
2

Le type de cette fonction est T -> (T -> U) -> U. Je crois que dans Haskell, ce serait quelque chose comme ($ . flip).Y a-t-il un nom commun pour la fonction f (a b) = b (a)?

Ou, dans une perspective orientée objet (ce qui est la façon dont je l'ai regardé il):

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

J'ai appelé il « dans » dans mes notes, et en utilisant un seul flèche (->) en tant qu'opérateur. Il est analogue à la fonction map, mais pour un scalaire:

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

Exemples d'applications pratiques:

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

Répondre

Questions connexes