This abbreviation for data modification

I get a warning for eta to reduce the following lambda expression.

\(DataType arg1 arg2) -> DataType (modify arg1) arg2

The Internet says that this reduction means giving up unnecessary lambdas.

map (\x -> fun x) list
map fun list

How does this apply to the above code? Perhaps I just lack the basic syntax for changing data types?

+4
source share
1 answer

In this case, you cannot reduce it. For lambda, there is only one argument, namely (DataType arg1 arg2). These are not separate arguments, as indicated by parentheses, but instead, you map the patterns to the constructor. In fact, the compiler will reduce this expression to more than

\arg -> case arg of
    DataType arg1 arg2 -> DataType (modify arg1) arg2

, , , . - -

\a b c -> f b a c

c , :

\a b -> f b a

, ,

flip f a b = f b a

flip f

( , flip Prelude).

, , $. , -

\a b c -> f a $ g b $ h c

:

\a b c -> (f a . g b . h) c

c

\a b -> f a . g b . h

, $ . .

, , , , , .

+5

All Articles