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›Introduction to Haskell

Introduction to Haskell

First step into Haskell, a purely functional language: main, printing with putStrLn, and the do block.

Simple enough for a 5-year-old to understand

print with putStrLn

Programs start from main. putStrLn prints text and moves to a new line.

Your first program
1
main = putStrLn "Hello!"
main is the start of the program.
Output / Inputmain is the start of the program.
Output / Input
💡 Hint: putStrLn prints text; print is used for numbers/structures.

Multiple lines: do

A do block is used to perform multiple operations in sequence.

Example code
1
main = do
Sequence operations with do.
FunctionSequence operations with do.
2
putStrLn "First"
Indentation (spaces) matters.
Output / InputIndentation (spaces) matters.
3
putStrLn "Second"
FunctionOutput / Input
💡 Hint: Lines in the do block must have the same indentation.

🎯 Exercise & Practice

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

1.Print exactly Hello World to the screen.

🎯 Expected output: Hello World

Loading editor…

About this topic

Haskell is a purely functional programming language. Born in 1990 as an academic research project, it is used today both in universities and in industrial projects where correctness is critical.

There are two key features that set Haskell apart from other languages. First is purity: a function always returns the same result for the same input and does not modify the outside world. Second is laziness: a value is not computed until it is actually needed.

Together, these two features eliminate many concepts you might be used to. There are no loops, variable values cannot change, and even printing to the screen is specially marked in the type system. At first it may seem restrictive; once you get used to it, you realize it makes the code's behavior much easier to predict.

What you will learn

  • The entry point of a Haskell program
  • printing to the screen with putStrLn
  • displaying values with print
  • Writing a type signature
  • Writing comment lines

Who is this for?

  • Those who want to learn functional programming
  • Those interested in type systems
  • Experienced developers looking for a different way of thinking

When to use?

Haskell excels in compiler writing, financial modeling, systems requiring verification, and complex transformation pipelines; its type system prevents a whole class of bugs from the start.

It is not suitable for rapid prototyping, simple scripts, or large team projects; its learning curve is steep and the library ecosystem is small.

Common mistakes

Wrong

main = putStrLn 42

putStrLn only prints text; when you pass a number, you get a type error similar to "No instance for (Num String)". Haskell does not automatically convert numbers to text. To print numbers, use print or convert the value to text first.

Correct

main = print 42

Wrong

main = do
putStrLn "one"
  putStrLn "two"

Indentation is meaningful in Haskell; expressions within a block must be aligned. This code results in a parse error due to inconsistent indentation. Because alignment is used instead of curly braces, spaces are part of the syntax.

Correct

main = do
  putStrLn "one"
  putStrLn "two"

Wrong

main = putStrLn "Number: " ++ show 5

Function application comes before the composition operator, so Haskell first applies the putStrLn function to the text and then tries to combine the result, resulting in a type error. To fix the precedence, parentheses or the application operator is used.

Correct

main = putStrLn ("Number: " ++ show 5)

Frequently asked questions

Why is learning Haskell considered difficult?

Because instead of transferring what you already know, you have to learn new concepts: recursion instead of loops, definition instead of assignment, type marking instead of side effects. The syntax is actually simple; the hard part is the shift in thinking.

Is it mandatory to write a type signature?

Not mandatory, the compiler can infer the type. But writing signatures for top-level definitions is a strong habit: it makes error messages clearer and documents what the code does. In the Haskell community, this is practically a rule.

What does laziness mean?

It means a value is not computed until its result is actually needed. This allows you to define infinite lists and only use the part you need. The trade-off is that memory usage can sometimes become hard to predict.

Summary

The program starts from the main definition.

putStrLn prints text, print outputs any showable value.

Indentation is part of the syntax.

Function application has the highest precedence.

Type signatures are optional but recommended.

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