Skip to content

Instantly share code, notes, and snippets.

@siers
Created April 24, 2021 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siers/1829f255a4d43638852b4309d1fe0791 to your computer and use it in GitHub Desktop.
Save siers/1829f255a4d43638852b4309d1fe0791 to your computer and use it in GitHub Desktop.
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