Lens Template Haskell data fields with suffix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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