Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The term "function application" in Haskell

I'm currently learning Haskell, and have encountered the term "function application" a couple of times, without really understanding what is meant by it.

Could someone try to explain the meaning of the term in Haskell, or eventually in general?

like image 928
Mr. Eivind Avatar asked Aug 28 '18 13:08

Mr. Eivind


People also ask

What is Haskell function type?

Haskell is a functional language and it is strictly typed, which means the data type used in the entire application will be known to the compiler at compile time.

Where is Haskell function?

Definition on Haskell Where Function. Haskell where is not a function rather it is a keyword that is used to divide the more complex logic or calculation into smaller parts, which makes the logic or calculation easy to understand and handle.


2 Answers

"Function application" here just means more or less the same thing as "passing an argument to the function". For example, if you have a function f :: Int -> Int and an x :: Int then f x :: Int is an expression where the expression x is "applied" as an argument to f *.

There is no real built-in operator for doing function application in Haskell (other than the whitespace that separates a function from its argument). Prelude exports the ($) function though, which is (some unusual oddities aside) just function application: i.e. ($) f x is the same as f x (this is mostly used for some syntactic tricks, although it occasionally has other uses as well)


*: It's been pointed out to me that people usually think of this in terms of applying a function to an argument rather than an argument to a function, I don't think this makes much difference for understanding the meaning of application here though

like image 101
Cubic Avatar answered Oct 11 '22 15:10

Cubic


It's mostly just standard English usage.

"Function application" is just application specifically of functions. "Application" in this context is just the noun corresponding to the verb "apply"; it means the act or process of applying something.

To "apply something" means to use it. To "apply A to B" means to do something to B using A. So "apply a function" means to use/call the function on something. In Haskell when I write the expression f x I am applying f to x.

Thus "function application" is just a term for the general concept of applying functions. In specific contexts it might be used to talk about:

  1. The broad notion of applying functions in general
  2. The syntax used to express "apply this function to that argument" in a programming language (e.g. "function application is by adjacency in Haskell", or "function application in Python uses C-like syntax")
  3. A specific bit of code that is applying a function
  4. In Haskell $ is often explained as "the function application operator", since f $ x = f x is more-or-less its definition

Or anything related.

like image 34
Ben Avatar answered Oct 11 '22 14:10

Ben