Haskell 如何替换';makeIso';新版本(4.3)中的旧镜头版本?
我有一些代码使用Haskell 如何替换';makeIso';新版本(4.3)中的旧镜头版本?,haskell,haskell-lens,Haskell,Haskell Lens,我有一些代码使用lens包中的makeIso: newtype Foo = Foo Integer makeIso Foo' incrementFoo :: Foo -> Foo incrementFoo = foo +~ 1 现在我想在4.3版的lens软件包中使用这段代码。 此版本缺少makeIso,更改日志显示: 删除了makeIsos,支持makePrisms和makelens。适当时,这些函数中的每一个都将构造Isos 因为从来没有像makeIsos这样的函数,我认为这是一个
lens
包中的makeIso
:
newtype Foo = Foo Integer
makeIso Foo'
incrementFoo :: Foo -> Foo
incrementFoo = foo +~ 1
现在我想在4.3版的lens
软件包中使用这段代码。
此版本缺少makeIso
,更改日志显示:
删除了makeIsos
,支持makePrisms
和makelens
。适当时,这些函数中的每一个都将构造Isos
因为从来没有像makeIsos
这样的函数,我认为这是一个拼写错误,它们的意思是makeIso
。因此,我试图用makelents
替换makeIso
,但这并没有创建一个fooIso
替换makeIso
的正确方法是什么
感谢您的帮助使用下划线定义访问者:
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
newtype Foo = Foo { _getFoo :: Integer } deriving Show
$(makeLenses ''Foo)
这将创建一个getFoo
iso:
getFoo :: (Profunctor p, Functor f) => p Integer (f Integer) -> p Foo (f Foo)
使用下划线定义访问器:
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
newtype Foo = Foo { _getFoo :: Integer } deriving Show
$(makeLenses ''Foo)
这将创建一个getFoo
iso:
getFoo :: (Profunctor p, Functor f) => p Integer (f Integer) -> p Foo (f Foo)
大概
makePrisms
将改为\u Foo
。大概makePrisms
将改为\u Foo
。