How to write comments in Haskell language? Comments are, explain single or multiple lines of a code

A developer can better understand the code by reading the comments. These are ignored at runtime.

In Kotlin, You can write a comment in different following ways.

  • Single-line comments
  • Multi-Line comments
  • Documentation commands

Haskell Single line comments

Single-line comments start with double hyphens, and spaces followed by a comment string.

--  comments text

Comments can be added in any single line or inline comments

-- hello world program
module Main where
main = putStrLn "Hello, World!" -- inline comments example

Haskell Multi-line comments

multi-line comments also called block comments. These comments start with {-, comment string span in multiple lines ends with -}

multi-line comment 1 example
multi-line comment 2 example

Haskell Documentation comments

Haddock is an API to document Haskell API code.

It is written with Haddock as a special comment annotation.

There are two types of documentation comments

  • pre comments: that starts with -- |. Haskell comment syntax with the pipe symbol
  • post comments : that starts with -- ^. single-line comment syntax with the ^ symbol
-- | sign function takes an integer and returns integer
-- return type is Int
Sign :: Int -> Int

-- ^ post documentation comment

Documentation comments are added to modules, classes, methods

How do you comment on Haskell?

You can write single or multi-line comments.

  • For Single line comments, the line starts with two hyphens, a space followed by a comment string.
  • For Multi line comments, the line always starts with {-, the comment string spans in multiple lines ends with -}

How do you comment on a block of code in Haskell?

The Block of code is placed in multiple lines. So multi-line comments are added with {- followed by space and string of text and ends with -}

block of code span in multiple lines.