{-# LANGUAGE TemplateHaskell #-} module SAML2.Lens ( fieldLens ) where import Control.Lens.Lens (lens) import qualified Language.Haskell.TH as TH fieldLens :: TH.Name -> TH.ExpQ fieldLens :: Name -> ExpQ fieldLens Name f = do Name a <- String -> Q Name forall (m :: * -> *). Quote m => String -> m Name TH.newName String "a" Name b <- String -> Q Name forall (m :: * -> *). Quote m => String -> m Name TH.newName String "b" Exp -> ExpQ forall a. a -> Q a forall (m :: * -> *) a. Monad m => a -> m a return (Exp -> ExpQ) -> Exp -> ExpQ forall a b. (a -> b) -> a -> b $ Name -> Exp TH.VarE 'lens Exp -> Exp -> Exp `TH.AppE` Name -> Exp TH.VarE Name f Exp -> Exp -> Exp `TH.AppE` [Pat] -> Exp -> Exp TH.LamE [Name -> Pat TH.VarP Name a, Name -> Pat TH.VarP Name b] (Exp -> [FieldExp] -> Exp TH.RecUpdE (Name -> Exp TH.VarE Name a) [(Name f, Name -> Exp TH.VarE Name b)])