Znatz
Znatz

Reputation: 1530

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 ?

Upvotes: 8

Views: 1570

Answers (1)

shachaf
shachaf

Reputation: 8930

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.

Upvotes: 9

Related Questions