Skip to content

Instantly share code, notes, and snippets.

@siers
Created April 24, 2021 19:49
Embed
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
@siers
Copy link
Author

siers commented Apr 24, 2021

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

https://hackage.haskell.org/package/brick-0.61/docs/src/Brick.Types.TH.html

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