Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Eta-conversions

Sumit Rawal answered on May 16, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers


Eta-conversions

0

That was the first invocation, methodA(f2). Now, about that second one, methodB(f2). This is where things get a bit more interesting. What Scala compiler just performed for us is called eta-expansion. There are two directions for this “eta operation”, as you will see soon. In literature, direction of eta-expansion is also sometimes called eta-abstraction, opposite direction is called eta-reduction, and they are both referred to under common term eta-conversion.

The idea behind eta-expansion is pretty simple. Having a function f(x), we normally refer to the function itself as f. For example, imagine we need to pass it to another function; we would pass simply f. Now, if instead of passing f we passed x ⇒ f(x), nothing would change, would it? Take the square function for example. We give it a 4, it returns a 16. Having this function is completely the same as having function x ⇒ sqr(x). We give it a 4, it returns a 16. We just “wrapped” our sqr function with another layer, resulting in another function. We can do this indefinitely:

Popularity 1/10 Helpfulness 1/10 Language scala
Source: Grepper
Tags: scala
Link to this answer
Share Copy Link
Contributed on May 16 2023
Sumit Rawal
0 Answers  Avg Quality 2/10


X

Continue with Google

By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
X
Grepper Account Login Required

Oops, You will need to install Grepper and log-in to perform this action.