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
if / then / elseGuards ( | )
🧩 Function
Haskell›REFERENCE›Condition
🔀

Condition

if-then-else (expression).

CommandDescription
if / then / elseProduces a value based on a condition.
Guards ( | )Multi-branch function definition.

if / then / else

Try it yourself →

Produces a value based on a condition.

Syntax

if condition then value1 else value2

Description

In Haskell, if is an EXPRESSION: both then and else are mandatory and both produce a value. even/odd tells if a number is even/odd.

Example

main = do
  let number = 7
  putStrLn (if even number then "even" else "odd")

Expected output

odd

When to use?

Branching, conditional value selection.

Common mistakes

  • ⚠️ An if cannot be written without else (if is an expression).

Guards ( | )

Try it yourself →

Multi-branch function definition.

Syntax

f x\n  | kosul1 = ...\n  | otherwise = ...

Description

Guards define a function based on conditions. The first matching branch is chosen; otherwise means 'if none match'.

Example

not_u :: Int -> String
not_u n
  | n >= 85 = "Excellent"
  | n >= 50 = "Passed"
  | otherwise = "Failed"
main = putStrLn (not_u 75)

Expected output

Passed

When to use?

Grade/category determination, multi-conditional logic.

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