我只是在学习 Yesod/Haskell。
在以下代码(http://www.yesodweb.com/book/restful-content)中有两件事我不明白(以及后续问题)。
{..}
- 这意味着什么?(谷歌很难找到这个词。)person@Person
-@
标志有什么作用?- 有没有一种方法可以让我找到难以理解的 Haskell 语法的答案,而不用在 StackOverflow 上打扰大家?
代码:
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
import Data.Text (Text)
import Yesod
data Person = Person
{ name :: Text
, age :: Int
}
instance ToJSON Person where
toJSON Person {..} = object
[ "name" .= name
, "age" .= age
]
data App = App
mkYesod "App" [parseRoutes|
/ HomeR GET
|]
instance Yesod App
getHomeR :: Handler TypedContent
getHomeR = selectRep $ do
provideRep $ return
[shamlet|
<p>Hello, my name is #{name} and I am #{age} years old.
|]
provideJson person
where
person@Person {..} = Person "Michael" 28
main :: IO ()
main = warp 3000 App