Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #18 from Peaker/master

Use early-binding for TH names (fmap, error, isomorphic) to avoid adding import dependencies to user code
  • Loading branch information...
commit e42ea61a1a6e2376e2a9cb322782cfdd6ebcd632 2 parents dc90d62 + 550e0f5
@ekmett authored
Showing with 5 additions and 5 deletions.
  1. +5 −5 src/Control/Lens/TH.hs
View
10 src/Control/Lens/TH.hs
@@ -142,21 +142,21 @@ freshMap ns = Map.fromList <$> for (toList ns) (\ n -> (,) n <$> newName (nameBa
makeIsoTo :: Name -> ExpQ
makeIsoTo conName = lamE [varP (mkName "f"), conP conName [varP (mkName "a")]] $
- appsE [ varE (mkName "fmap")
+ appsE [ return (VarE 'fmap)
, conE conName
, varE (mkName "f") `appE` varE (mkName "a")
]
makeIsoFrom :: Name -> ExpQ
makeIsoFrom conName = lamE [varP (mkName "f"), varP (mkName "a")] $
- appsE [ varE (mkName "fmap")
+ appsE [ return (VarE 'fmap)
, lamE [conP conName [varP (mkName "b")]] $ varE (mkName "b")
, varE (mkName "f") `appE` (conE conName `appE` varE (mkName "a"))
]
makeIsoBody :: Name -> Name -> (Name -> ExpQ) -> (Name -> ExpQ) -> DecQ
makeIsoBody lensName conName f g = funD lensName [clause [] (normalB body) []] where
- body = appsE [ varE (mkName "isomorphic")
+ body = appsE [ return (VarE 'isomorphic)
, f conName
, g conName
]
@@ -261,7 +261,7 @@ commonFieldDescs = toList . Prelude.foldr walk mempty where
errorClause :: Name -> Name -> Name -> ClauseQ
errorClause lensName fieldName conName
- = clause [] (normalB (varE (mkName "error") `appE` litE (stringL err))) []
+ = clause [] (normalB (return (VarE 'error) `appE` litE (stringL err))) []
where
err = show lensName ++ ": no matching field "
++ show fieldName ++ " in constructor "
@@ -280,7 +280,7 @@ makeFieldLensBody lensName fieldName cons maybeMethodName = case maybeMethodName
f <- newName "f"
x <- newName "y"
clause [varP f, conP conName $ map varP names] (normalB
- (appsE [ varE (mkName "fmap")
+ (appsE [ return (VarE 'fmap)
, lamE [varP x] $ appsE $ conE conName : map varE (element i .~ x $ names)
, varE f `appE` varE (names^.element i)
])) []
Please sign in to comment.
Something went wrong with that request. Please try again.