假设我有一个持久类型,并希望从该类型中投射一些值:
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
User
name Text
email Text
|]
...
getName :: Entity User -> Text
getName (Entity uid vals) = userName vals
问题是,如果我为所述类型生成镜头,使用mkPersist sqlSettings {mpsGenerateLenses = True}
,我需要在每个投影函数的开头添加下划线或使用镜头吸气剂:
getName :: Entity User -> Text
getName (Entity uid vals) = _userName vals
getName' :: Entity User -> Text
getName (Entity uid vals) = vals ^. userName
- 首先,如何将其恢复为默认值,
userName vals
并添加下划线以使用镜头吸气剂,vals ^. _userName
? - 其次,为什么是这样而不是相反?