How to write a multiline comment in Haskell

Overview

Comments are non-executable statements that are used to describe the program. They are useful while reviewing another's code because they help us to understand the logic behind the code.

Each language uses a different syntax to add the comments the source code. We will use the syntax below to add the comment in Haskell.

Syntax

Let’s have a look at the syntax for the single line and multiline comment.

Single line comment

-- Use two hyphens to comment a single line of code.

Multiline comment

{-
This is the syntax of multiline comments in haskell
-}

Multiline comments start with a flower bracket and a hyphen, {-, and close with a hyphen and a flower bracket -}. We'll add comments to the lines between.

Let us take a look at an example below.

Example

main :: IO()
main = do
{-
print("This line won't print")
print("This line is commented using multiline comment syntax"
-}
print("Hello World")

Explanation

  • Lines 4–7: We add comments to these lines using multiline syntax so the compiler will ignore the statements present in it.

Free Resources