Skip to content

0018: Email Tutorials Haskell For Beginners – Prefix to Infix Functions (Using Backticks) in Haskell

Bernard Sibanda edited this page Dec 8, 2025 · 4 revisions

🎥 LigerLearn Vedio 18

📑 Table of Contents

18.1. Three Possible Positions for Function Names 18.2. Prefix Functions – The Default in Haskell 18.3. Infix Functions – Placing the Function Between Arguments 18.4. Backticks: Turning Any Prefix Function into Infix 18.5. When Backticks Make Code More Readable 18.6. Backticks with Functions of More Than Two Arguments 18.7. Common Beginner Mistakes 18.8. Glossary of Terms

18.1. Three Possible Positions for Function Names

In general programming theory, functions can appear in:

  1. Prefix position – function before arguments
  2. Infix position – function between arguments
  3. Postfix position – function after arguments

Haskell supports prefix and infix, but never postfix. Postfix is mentioned only for completeness.

18.2. Prefix Functions – The Default in Haskell

Most Haskell functions are called like this:

div 20 2
odd 5
add_three_doubles 1.2 4.5 7.1

This is because prefix style is the standard. It fits nicely with:

  • Functions of many arguments
  • Partial application
  • Higher-order functions

18.3. Infix Functions – Placing the Function Between Arguments

We have already seen many infix functions:

2 + 3
5 - 1
6 * 7

Haskell also uses infix for Boolean operators:

x && y
x || y
x == y

These operators are built-in infix functions.

18.4. Backticks: Turning Any Prefix Function into Infix

The cool part:

ANY function of two arguments can be written infix-style ➡ Just put the function name in backticks (`)

Example:

Prefix form:

div 20 2

Infix form (using backticks):

20 `div` 2

Both compute:

10

This can make code more readable, because you can literally read it as:

“20 divided by 2”

18.5. When Backticks Make Code More Readable

Using backticks is great when:

  • There are exactly two arguments
  • The function expresses a natural relation or operation

Examples:

x `max` y
a `compare` b
value `elem` list

These read like English sentences.

18.6. Backticks with Functions of More Than Two Arguments

It is technically possible, but usually not worth doing.

Example function:

add_three_doubles :: Double -> Double -> Double -> Double
add_three_doubles x y z = x + y + z

Prefix style:

add_three_doubles 1.0 2.0 3.0

Infix style with backticks (awkward):

(1.0 `add_three_doubles` 2.0) 3.0

You must wrap the first call in parentheses; otherwise Haskell will think you're trying to apply too many arguments.

Conclusion: Backticks are best reserved for binary functions only.

18.7. Common Beginner Mistakes

❌ Forgetting the backticks

20 div 2    -- WRONG in infix form

❌ Using apostrophes instead of backticks

Backtick: ` Apostrophe: '

❌ Trying to infix a function with one argument

`not` True    -- doesn’t work because not only has 1 argument

❌ Using backticks with more than two arguments without parentheses

1.0 `add_three_doubles` 2.0 3.0  -- WRONG

18.8. Glossary of Terms

  • Prefix Function Function name comes before its arguments. Default style in Haskell.

  • Infix Function Function name appears between two arguments. Usually used for arithmetic and comparison.

  • Backticks (`) Syntax used to turn a prefix function of two arguments into infix form.

  • Postfix Function name appears after arguments. Not used in Haskell.

  • Binary Function A function that takes exactly two arguments. Works best with infix/backticks.

  • Operator A symbolic function normally used infix, e.g. (+), (-), (==).

Quizz & Progress Badge NFT

Clone this wiki locally