如果我有一个
newtype
newtype Foo = Foo Int
有没有自动的方法来获取一个Iso' Foo Int
?
我看到可以使用makeLenses ''Foo
,但我不知道生成的iso的名称是什么。
newtype
newtype Foo = Foo Int
有没有自动的方法来获取一个Iso' Foo Int
?
我看到可以使用makeLenses ''Foo
,但我不知道生成的iso的名称是什么。
newtype Foo = Foo {_unFoo :: Int}
,然后执行makeLenses ''Foo
,它将生成你想要的Iso并命名为"unFoo"。请注意,访问器必须以下划线开头才能生成Iso。