Skip to content

Instantly share code, notes, and snippets.

Created April 24, 2021 19:49
What would you like to do?
Lens Template Haskell data fields with suffix
import Control.Lens.Internal.FieldTH (makeFieldOptics, LensRules(..))
import Language.Haskell.TH.Syntax (mkName, nameBase)
import Control.Lens.TH (DefName(..), lensRules)
data Field = { a :: Int, b :: Int }
makeFieldOptics lensRules { _fieldToDef = (\_ _ -> (:[]) . TopName . mkName . (++ "L") . nameBase) } ''Field
-- hopefully someone find this useful
Copy link

siers commented Apr 24, 2021

Oh, now that I've implemented it myself, I see someone else implemented it as well... 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment