开发者

What manner of Haskell syntax is used in [$parseRoutes|/ Home GET|]?

开发者 https://www.devze.com 2023-01-08 12:24 出处:网络
I found this code on the front page of the Yesod project: import Yesod data HelloWorld = HelloWorld mkYesod \"HelloWorld\" [$parseRoutes|/ Home GET|]

I found this code on the front page of the Yesod project:

import Yesod
data HelloWorld = HelloWorld
mkYesod "HelloWorld" [$parseRoutes|/ Home GET|]
instance Yesod He开发者_高级运维lloWorld where approot _ = ""
getHome = applyLayout [$hamlet|%h1 Hello World|]
main = toWaiApp HelloWorld >>= basicHandler 3000

What language features are used in [$parseRoutes|/ Home GET|] and [$hamlet|%h1 Hello World|] to get the $, |, / and % symbols working, and what do the symbols do?


Those would be a Quasiquotation. It's a way to use Template Haskell to embed another language into Haskell. The quasiquotes 'parseRoutes and hamlet define how to parse and interpret what is inside the bracket [$FOO| ... ]. Many more details at the link above.

0

精彩评论

暂无评论...
验证码 换一张
取 消