Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does these square brackets in Haskell?

I read the code below in Indexed Monad

{-# LANGUAGE QuasiQuotes #-}
import Control.Monad.Indexed.State
import Control.Monad.Indexed
import Language.Haskell.IndexedDo

hoge :: IxState Int [Int] ()
hoge = [ido|do
    imodify (*10)
    imodify show
    imodify reverse
    imodify (++"123")
    imodify $ map fromEnum
    |]

What is the syntax of these symbols [|....|] ?

Is it some kind of syntax sugar ?

like image 455
Znatz Avatar asked May 05 '13 07:05

Znatz


People also ask

What does square brackets mean in Haskell?

In Haskell, a list is a data structure that can store multiple items of the same type. For example, a list of integers or a list of characters. A string in Haskell is considered to be a list of characters. Square brackets are used to define a list.

What do [] brackets indicate?

Brackets are symbols that we use to contain "extra information", or information that is not part of the main content. Brackets always come in pairs—an "opening" bracket before the extra information, and a "closing" bracket after it. There are two main types of bracket: round () and square [].

What are [] used for in writing?

Brackets are used to insert explanations, corrections, clarifications, or comments into quoted material. Brackets are always used in pairs; you must have both an opening and a closing bracket.

What do parenthesis () and square bracket [] In differ?

Generally, 'parentheses' refers to round brackets ( ) and 'brackets' to square brackets [ ]. However, we are more and more used to hearing these referred to simply as 'round brackets' or 'square brackets'. Usually we use square brackets - [ ] - for special purposes such as in technical manuals.


1 Answers

This is quasiquotation syntax. See also the wiki page. The text between [ido| and |] is passed verbatim to the quasiquoter ido, which uses it to generate some Haskell code at compile-time.

like image 200
shachaf Avatar answered Nov 03 '22 18:11

shachaf