Created
April 24, 2021 19:49
-
-
Save siers/1829f255a4d43638852b4309d1fe0791 to your computer and use it in GitHub Desktop.
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