applicative-quoters 0.1.0.4 → 0.1.0.5
raw patch · 3 files changed
+25/−3 lines, 3 filesdep ~base
Dependency ranges changed: base
Files
- Control/Applicative/QQ/ADo.hs +3/−2
- Magic.hs +19/−0
- applicative-quoters.cabal +3/−1
Control/Applicative/QQ/ADo.hs view
@@ -167,9 +167,10 @@ -- Uses lookupValueName when available via TH magic, otherwise tries a -- best-guess approach (see the caveats section)--- | Finds a 'TyConI dec' corresponding to the given name, and returns 'dec'+-- | Given a 'Name' of a value constructor, find the 'TyConI dec' of its+-- type, and return 'dec' findTyCon :: Name -> Q Dec-findTyCon n = case $maybeLookupValueName of+findTyCon n = case $(maybeVar "lookupValueName") of Just fn -> do DataConI _ _ tn _ <- maybe noScope reify =<< fn (show n) TyConI dec <- reify tn
+ Magic.hs view
@@ -0,0 +1,19 @@+{-# LANGUAGE TemplateHaskell #-}+-- This stuff has to be in a separate module because of the stage restriction.+module Magic where++import Language.Haskell.TH++-- | 'return's 'Just (VarE n)' if 'n' names a variable in scope, or+-- 'Nothing' if 'n' is not in scope or is not a variable.+findVar :: Name -> Q (Maybe Exp)+findVar name = recover (return Nothing) $ do+ VarI n _ _ _ <- reify name+ return (Just (VarE n))++-- | Returns a Q Exp which expands to Just lookupValueName if lookupValueName+-- exists, or Nothing if it doesn't.+maybeVar :: String -> Q Exp+maybeVar s = findVar (mkName s) >>= \e -> case e of+ Nothing -> [| Nothing |]+ Just expr -> [| Just $(return expr) |]
applicative-quoters.cabal view
@@ -1,7 +1,7 @@ Cabal-Version: >= 1.6 Name: applicative-quoters-Version: 0.1.0.4+Version: 0.1.0.5 Category: Language Synopsis: Quasiquoters for idiom brackets and an applicative do-notation @@ -23,6 +23,8 @@ Exposed-modules: Control.Applicative.QQ.ADo Control.Applicative.QQ.Idiom+ Other-modules:+ Magic Build-depends: base >= 4 && < 4.6,