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 ?
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.
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 [].
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With