I have some code which uses makeIso
from the lens
package:
newtype Foo = Foo Integer
makeIso Foo'
incrementFoo :: Foo -> Foo
incrementFoo = foo +~ 1
Now I would like to use this code with the 4.3 version of the lens
package.
This version lacks makeIso
and the changelog says:
Removed
makeIsos
in favor ofmakePrisms
andmakeLenses
. Each of these functions will constructIsos
when appropriate.
Because there never was such a function as makeIsos
I think it's a spelling mistake and they mean makeIso
. So I tried to replace makeIso
by makeLenses
but that doesn't create a foo Iso
.
What is the correct way to replace makeIso
?
Thanks for your help
Define an accessor with an underscore:
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
newtype Foo = Foo { _getFoo :: Integer } deriving Show
$(makeLenses ''Foo)
This will create a getFoo
iso:
getFoo :: (Profunctor p, Functor f) => p Integer (f Integer) -> p Foo (f Foo)