applicative-quoters 0.1 → 0.1.0.1
raw patch · 3 files changed
+47/−10 lines, 3 filesdep ~haskell-src-meta
Dependency ranges changed: haskell-src-meta
Files
- Control/Applicative/QQ/ADo.hs +44/−7
- Control/Applicative/QQ/Idiom.hs +1/−1
- applicative-quoters.cabal +2/−2
Control/Applicative/QQ/ADo.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE TemplateHaskell #-} --- | Applicative do. Phillipa Cowderoy's idea, some explanations due Edward+-- | Applicative do. Philippa Cowderoy's idea, some explanations due Edward -- Kmett -- -- Pointful version of "Language.Haskell.Meta.QQ.Idiom". Note the only@@ -19,10 +19,13 @@ -- * Desugaring -- $desugaring++ -- * Caveats+ -- $caveats ) where import Control.Applicative-import Language.Haskell.Meta+import Language.Haskell.Meta (parseExp) import Language.Haskell.TH.Lib import Language.Haskell.TH.Quote import Language.Haskell.TH.Syntax@@ -64,6 +67,19 @@ -- -- > foo = (\ ~(x:xs) (A y) -> T x y) <$> foo bar baz <*> quux quaffle +-- $caveats+--+-- Template Haskell is currently unable to reliably look up constructor names+-- just from a string: if there is a type with the same name, it will+-- return information for that instead. This means that the safe version of+-- 'ado' is prone to failure where types and values share names. It tries to+-- make a \"best guess\" in the common case that type and constructor have the+-- same name, but has nontrivial failure modes. In such cases, 'ado'' should+-- work fine: at a pinch, you can bind simple variables with it and case-match+-- on them in your last statement.+--+-- See also: <http://hackage.haskell.org/trac/ghc/ticket/4429>+ -- | Usage: -- -- > ghci> [$ado| a <- "foo"; b <- "bar"; (a,b) |]@@ -109,9 +125,9 @@ LetS _ -> fail $ "LetS not supported" ParS _ -> fail $ "ParS not supported" - fps <- filterM failingPattern ps+ b <- if rawPatterns then return True else null <$> filterM failingPattern ps - f' <- if rawPatterns || null fps+ f' <- if b then return $ LamE ps f else do xs <- mapM (const $ newName "x") ps@@ -146,11 +162,32 @@ singleCon :: Name -> Q Bool singleCon n = do- DataConI _ _ tn _ <- reify n- TyConI dec <- reify tn+ info <- reify n+ -- This covers the common case of a data type with one of the+ -- constructors being named the same as the type, but fails if there+ -- is a type Foo and a constructor Foo of a different type :(+ TyConI dec <- case info of+ DataConI _ _ tn _ -> reify tn+ -- we hope that the base of the tn is the same, but it is+ -- properly qualified+ TyConI (DataD _ _ _ cs _)+ | any ((nameBase n ==) . nameBase . conName) cs -> return info+ | otherwise -> errShadow+ TyConI (NewtypeD _ _ _ c _)+ | nameBase n == nameBase (conName c) -> return info -- eventually True+ | otherwise -> errShadow+ _ -> fail $ "ado singleCon: not a constructor: " ++ show info case dec of DataD _ _ _ [_] _ -> return True NewtypeD {} -> return True DataD _ _ _ (_:_) _ -> return False- _ -> fail $ "Bad dec: "++show dec+ _ -> fail $ "ado singleCon: not a data declaration: " ++ show dec+ where+ errShadow = fail . concat $ ["ado singleCon: couldn't find data ",+ "dec for name: ", show n, ", sorry :( - try using ado' instead"] +conName :: Con -> Name+conName (NormalC n _) = n+conName (RecC n _) = n+conName (InfixC _ n _) = n+conName (ForallC _ _ c) = conName c
Control/Applicative/QQ/Idiom.hs view
@@ -5,7 +5,7 @@ module Control.Applicative.QQ.Idiom (i) where import Control.Applicative-import Language.Haskell.Meta+import Language.Haskell.Meta (parseExp) import Language.Haskell.TH.Lib import Language.Haskell.TH.Quote import Language.Haskell.TH.Syntax
applicative-quoters.cabal view
@@ -1,7 +1,7 @@ Cabal-Version: >= 1.6 Name: applicative-quoters-Version: 0.1+Version: 0.1.0.1 Category: Language Synopsis: Quasiquoters for idiom brackets and an applicative do-notation @@ -26,7 +26,7 @@ Build-depends: base >= 4 && < 4.4,- haskell-src-meta >= 0.2 && < 0.4,+ haskell-src-meta >= 0.2 && < 0.5, template-haskell >= 2.4 && < 2.6 -- We disable the missing-fields warning because not only do quoteType