10

I have Array of Array of strings. I need to flatten them and I use:

Array.fold (fun acc el -> Array.append acc el) [||] arr2d

Lint says me that:

"If Array.append has not mutable arguments partially applied then the lambda can be removed"

What does it mean? How can I remove lambda?

user990423
  • 1,397
  • 2
  • 12
  • 32
ceth
  • 44,198
  • 62
  • 180
  • 289

1 Answers1

12

Any lambda function in that form (fun x -> f x) can be expressed as f. Holding immutable condition.

In your code you have fun acc el -> Array.append acc el which has the same type and does the same as Array.append, so you can shorten it to:

Array.fold Array.append [||] arr2d
trincot
  • 317,000
  • 35
  • 244
  • 286
Bartek Kobyłecki
  • 2,365
  • 14
  • 24
  • 1
    Haskell guys call that transformation [eta reduction](http://stackoverflow.com/questions/5793843/what-does-eta-reduce-mean-in-the-context-of-hlint). – scrwtp Nov 24 '15 at 19:19
  • @scrwtp Not just Haskell guys, this is [the standard lambda-calculus name for it](https://en.wikipedia.org/wiki/Lambda_calculus#.CE.B7-conversion). – Alexey Romanov Dec 07 '15 at 13:22
  • @AlexeyRomanov: yes, but only Haskell guys call it that way in the open ;) – scrwtp Dec 07 '15 at 15:29
  • @scrwtp Counter-example: http://caml.inria.fr/pub/old_caml_site/FAQ/FAQ_EXPERT-eng.html :) – Alexey Romanov Dec 07 '15 at 18:53