Eta reduction removes a redundant parameter and its immediate application: an expression such as (\x -> f x) becomes f. Repeating this transformation lets function definitions omit trailing parameters and become more concise. section 4.2.1
The technique works naturally with partial application. Applying const to True produces a function that ignores its argument and returns True: const True has type b -> Bool. Removing the final parameter from numberAllLines is therefore valid because numberLines (const True) (const True) already has the required list-processing type. section 4.2.1
Concise line-numbering functions
The explicit definition numberAllLines text = numberLines (const True) (const True) text can be eta-reduced to numberAllLines = numberLines (const True) (const True). The same style produces variants that number every line, number only nonempty lines, or number and increment only nonempty lines. section 4.2.1 section 4.5
Listing 4.6 Three variants for functions that number lines based on different conditions
numberAllLines :: [String] -> NumberedLines numberAllLines = numberLines (const True) (const True) #1 numberNonEmptyLines :: [String] -> NumberedLines numberNonEmptyLines = numberLines (const True) isNotEmpty #2 numberAndIncrementNonEmptyLines :: [String] -> NumberedLines numberAndIncrementNonEmptyLines = numberLines isNotEmpty isNotEmpty #3
Compare three progressively specialized eta-reduced definitions and their use of partially applied predicates. section 4.2.1
