🎓 A1Learner
🔍
0 of 54 lessons completed

Haskell Comments

A comment is a note inside code that the compiler ignores. Comments explain code to people who read it later.

A line comment is ignored

The note starts with -- on its own line. Only the printing action runs.

-- This program says hello
main :: IO ()
main = putStrLn "Hello"

A block comment can span lines

The note opens with {- and closes with -}. The compiler skips the whole block.

{- This note explains the program.
   It covers two lines. -}
main :: IO ()
main = print 10

A comment can explain a value

The comment sits above the line it explains. The line below it still runs as normal.

-- The number the program prints
main :: IO ()
main = print 25

Example

-- A short greeting program
{- The main action prints
   one line of text. -}
main :: IO ()
main = putStrLn "Comments explain code"

Key points

  • Line comment: a note that starts with -- and runs to the end of the line.
  • Block comment: a note that starts with {- and ends with -}.
  • Block comments can cover several lines in one note.
  • Ignored code: the compiler skips every comment when it builds the program.
  • Output: a comment never prints anything by itself.

In this example, a line comment gives the program a title. A block comment then explains the main action, and putStrLn prints the greeting.

Note

comments are for readers, so keep them short and useful.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Haskell Playground

Exercise

How does a line comment start in Haskell?