-
Notifications
You must be signed in to change notification settings - Fork 4
0018: Email Tutorials Haskell For Beginners – Prefix to Infix Functions (Using Backticks) in Haskell
- 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
In general programming theory, functions can appear in:
- Prefix position – function before arguments
- Infix position – function between arguments
- Postfix position – function after arguments
Haskell supports prefix and infix, but never postfix. Postfix is mentioned only for completeness.
Most Haskell functions are called like this:
div 20 2
odd 5
add_three_doubles 1.2 4.5 7.1This is because prefix style is the standard. It fits nicely with:
- Functions of many arguments
- Partial application
- Higher-order functions
We have already seen many infix functions:
2 + 3
5 - 1
6 * 7Haskell also uses infix for Boolean operators:
x && y
x || y
x == yThese operators are built-in infix functions.
The cool part:
➡ ANY function of two arguments can be written infix-style
➡ Just put the function name in backticks (`)
Example:
div 20 220 `div` 2Both compute:
10This can make code more readable, because you can literally read it as:
“20 divided by 2”
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` listThese read like English sentences.
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 + zadd_three_doubles 1.0 2.0 3.0(1.0 `add_three_doubles` 2.0) 3.0You 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.
20 div 2 -- WRONG in infix formBacktick: `
Apostrophe: '
`not` True -- doesn’t work because not only has 1 argument1.0 `add_three_doubles` 2.0 3.0 -- WRONG-
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.
(+),(-),(==).
Bernard Sibanda is a global Technology Entrepreneur, Web3 and Software Consultant with a deep focus on Cardano Blockchain, Midnight and Community building.
Key Positions:
- Founder, CTO, Developer Advocate cohort #1, Fullstake Developer, Cardano Ambassador, Catalyst Project Manager, DREP-WIMS:
- Co-founder of ABL Tech and Cardano Africa Live
- EBU-certified Plutus Pioneer (Plutus/Haskell)
- Cohort #1 Plutus Pioneer Developer
- Catalyst Community Reviewer & Funded Projects Manager
-
DRep for WIMS-Cardano (ID:
drep1yguj8zu48n99pv70yl6ckzt9hdgjy8yjnlqs2uyzcpafnjgu4vkul) - Intersect Developer Advocate
- Intersect Committe Member 2025-2026
- Cardano Marketer,Promoter and blogger
- Cardano Open Source Contributor
- Cardano communities and events organizer and builder
- Cardano Ambassador for South Africa
Official links:
- Stablecoins Dex
- Coxygen Global Universities
- WIMS Cardano Global
- Cardano Africa Live
- WIMS Cardano Videos
- Cardano Smart Contract Videos
- Fullstack IT Consulting
Social links: