felix-eku
felix-eku

Reputation: 2213

How to replace 'makeIso' from the older lens versions in the new version (4.3)?

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 of makePrisms and makeLenses. Each of these functions will construct Isos 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

Upvotes: 2

Views: 125

Answers (1)

danidiaz
danidiaz

Reputation: 27766

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)

Upvotes: 4

Related Questions