在使用Optics包学习 Haskell 镜头时,我遇到了以下示例:
data Person = Person
{ _name :: String
, _age :: Int
}
makeLenses ''Person
makePrisms 'Person
类型的值Name
代表什么,单引号和双引号/撇号之间有什么区别?
两者似乎具有相同的类型:
makeLenses, makePrisms :: Name -> DecsQ
模板-haskell 文档对我来说是不可理解的。它侧重于语法,缺乏示例:
* 'f has type Name, and names the function f. Similarly 'C has type Name and names the data constructor C. In general '⟨thing⟩ interprets ⟨thing⟩ in an expression context.
* ''T has type Name, and names the type constructor T. That is, ''⟨thing⟩ interprets ⟨thing⟩ in a type context.