Last active
August 20, 2020 11:54
-
-
Save paolino/fb0926f236d26696d91f29937e09f8ad to your computer and use it in GitHub Desktop.
This file contains hidden or 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
{- | |
dependencies: | |
- lens | |
- template-haskell | |
create all lenses for a record type preponing an l_ instead of removing the underscore | |
-} | |
import Control.Lens ((.~), lensRules, lensField, makeLensesWith, DefName(TopName), FieldNamer) | |
import Language.Haskell.TH (DecsQ, Name, nameBase, mkName) | |
allLNamer :: FieldNamer | |
allLNamer _ _ n = pure $ TopName $ mkName ('l': '_' : nameBase n) | |
makeLLenses :: Name -> DecsQ | |
makeLLenses = makeLensesWith (lensField .~ allLNamer $ lensRules ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment