I'm talking mostly about functional programming languages. For example, the wikipedia article for map has this example in a Haskell-ish language:
map square [1,2,3,4,5]
How does the parser/compiler know that we want to pass the function square
to map
as a higher-order function, and not trying to invoke the function itself? For languages with static typing, the expression square [1,2,3,4,5]
obviously wouldn't compile, but would a compiler really use that to determine that's not what I meant?
Or, is this just a bad example from Wikipedia, and a better example might look like map &square [1,2,3,4,5]
(using C-style function referencing)?