HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to HaskellVariables (let)Data TypesOperatorsStringsListsConditions (if / then / else)Iteration (map / sum)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Value & Type
🔢 Numbers & Math
✍️ String
📚 List
🔀 Condition
🧩 Function
Haskell›Operators

Operators

Math (+ - * div mod), comparison (== < >), and logic (&& || not).

Simple enough for a 5-year-old to understand

Math operators

Integer division uses div, and remainder uses mod. / works only with floating-point (Double) numbers.

Example code
1
main = do
2
print (7 + 3)
10
Output / Input10
3
print (div 7 2)
3 (integer division)
Output / Input3 (integer division)
4
print (mod 7 2)
1 (remainder)
Output / Input1 (remainder)
5
print (7.0 / 2.0)
3.5 (floating-point division)
Output / Input3.5 (floating-point division)
Output / Input
💡 Hint: In Int, division uses div and remainder uses mod; / is only for Double.

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (1 left)

1.Print the remainder of the division of 23 by 4.

🎯 Expected output: 3

Loading editor…

About this topic

In Haskell, operators are actually functions; the difference is that they are written between two operands. You can use an operator with parentheses like a regular function anytime, and a function with backticks like an operator.

This flexibility increases code readability. Operations like remainder finding or integer division are defined as functions, but when written inside backticks, they resemble mathematical expressions.

Two Haskell-specific operators must be learned. The application operator reduces parenthesis clutter; the composition operator combines two functions to produce a new one. Both create the characteristic look of Haskell code.

What you will learn

  • Arithmetic and comparison operators
  • The syntax of the inequality operator
  • The list concatenation operator
  • Application and composition operators
  • Using a function like an operator

Who is this for?

  • Developers coming from the C family
  • Those who want to get rid of parenthesis clutter
  • Those who make mistakes in operator precedence

When to use?

When consecutive transformations are written with the composition operator, the intent is visible at a glance.

In long expressions, the application operator increases readability by eliminating nested parentheses.

Common mistakes

Wrong

main = print (5 != 3)

In Haskell, the not-equal operator is written with a slash and an equals sign; the exclamation mark form is not defined and results in a scope error. This is a difference that those coming from the C family encounter on the first day.

Correct

main = print (5 /= 3)

Wrong

main = print ([1, 2] + [3, 4])

The plus operator is for numerical addition and is not defined on lists; a "No instance for (Num [a])" error is thrown. There is a separate operator for list concatenation. The same distinction applies to strings, because a string is a list of characters.

Correct

main = print ([1, 2] ++ [3, 4])

Wrong

main = print negate 5

Since function application has the highest precedence, Haskell reads this as a print call with two arguments and throws a type error. Grouping the argument requires parentheses or the application operator; the latter is more common in Haskell code.

Correct

main = print $ negate 5

Frequently asked questions

What exactly does the application operator do?

It passes the entire expression on its right as a single argument to the function on its left. It has low precedence, so it acts like parentheses. In long chains, it completely eliminates unmatched parenthesis errors.

What is the purpose of the composition operator?

It combines two functions to produce a new one: first the right one is applied, then the left one. It allows you to build a transformation chain without defining intermediate variables and is the most prominent writing style of functional code.

Can I define my own operator?

Yes, you can define a function with a name consisting of symbols and specify its precedence. Libraries do this frequently; however, overuse makes the code unreadable, so it should be used in moderation.

Summary

Operators are actually functions.

The not-equal operator is written with a slash.

List and string concatenation is a separate operator.

Function application has the highest precedence.

Application and composition operators simplify the code.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code