【发布时间】:2020-05-23 09:17:03
【问题描述】:
如果我有newtype
newtype Foo = Foo Int
有没有自动获取Iso' Foo Int的方法?
我看到我可以使用makeLenses ''Foo,但我不知道生成的iso的名称是什么。
【问题讨论】:
标签: haskell haskell-lens lenses
如果我有newtype
newtype Foo = Foo Int
有没有自动获取Iso' Foo Int的方法?
我看到我可以使用makeLenses ''Foo,但我不知道生成的iso的名称是什么。
【问题讨论】:
标签: haskell haskell-lens lenses
如果您将访问器命名为:newtype Foo = Foo {_unFoo :: Int},然后执行 makeLenses ''Foo,它将在名称“unFoo”下生成您想要的 Iso
请注意,访问器必须以下划线开头才能生成 Iso。
【讨论】: