πŸŽ“ A1Learner
πŸ”
0 of 54 lessons completed

Haskell Introduction

Haskell is a programming language for building programs from values and expressions. A Haskell program starts at a special entry point named main.

A program can print text

The entry point uses putStrLn to print a line of text. The text sits inside double quotes.

main :: IO ()
main = putStrLn "Hello, Haskell!"

A program can print a number

The print action prints a number value. No quotes are needed around a number.

main :: IO ()
main = print 42

A calculation prints its result

Haskell works out the calculation inside print first. It then prints the result.

main :: IO ()
main = print (3 + 4)

Example

main :: IO ()
main = putStrLn "Welcome to Haskell"

Key points

  • Program: a set of instructions that the computer follows.
  • Value: a piece of data, such as a number or a line of text.
  • Expression: a piece of code that works out a value.
  • main: the starting point where every Haskell program begins.
  • putStrLn: an action that prints text and then moves to a new line.
  • print: an action that prints a value and then moves to a new line.

In this example, the main signature marks the entry point. The main action uses putStrLn to print the welcome text.

Note

Haskell programs describe what a result is, rather than listing step-by-step changes.

Try it Yourself

Edit the code, then press Run.

Running is simulated Β· Haskell Playground

Exercise

What is the starting point of every Haskell program in this course?