Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does a Haskell comment starting with `{- |` generally mean?

I see Haskell multi-line comments that sometimes start with {- | instead of just {-.

Does leading with the pipe character inside the comment mean something by convention?

like image 261
dan Avatar asked Jan 11 '13 02:01

dan


People also ask

How do you comment in Haskell code?

The “-- |” syntax begins a documentation annotation, which applies to the following declaration in the source file. Note that the annotation is just a comment in Haskell — it will be ignored by the Haskell compiler.

What does <$> mean in Haskell?

It's merely an infix synonym for fmap , so you can write e.g. Prelude> (*2) <$> [1.. 3] [2,4,6] Prelude> show <$> Just 11 Just "11" Like most infix functions, it is not built-in syntax, just a function definition. But functors are such a fundamental tool that <$> is found pretty much everywhere.

What does A -> B mean in Haskell?

a -> b Bool means... forall (a :: *) (b :: * -> *). a -> b Bool. b is therefore a type constructor taking a single type argument. Examples of single-argument type constructors abound: Maybe , [] , IO are all examples of things which you could use to instantiate b .

What does AT symbol mean in Haskell?

The @ Symbol is used to both give a name to a parameter and match that parameter against a pattern that follows the @ . It's not specific to lists and can also be used with other data structures.


1 Answers

The | at the start of a comment is Haddock syntax that begins a documentation annotation. An example from the Haddock documentation is:

-- |The 'square' function squares an integer. square :: Int -> Int square x = x * x 

It also goes on to say

The “-- |” syntax begins a documentation annotation, which applies to the following declaration in the source file. Note that the annotation is just a comment in Haskell — it will be ignored by the Haskell compiler.

like image 181
Lily Ballard Avatar answered Sep 22 '22 00:09

Lily Ballard