th-lift 0.7.5 → 0.7.6
raw patch · 3 files changed
+37/−5 lines, 3 filesdep ~template-haskellPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: template-haskell
API changes (from Hackage documentation)
Files
- Changelog +10/−0
- src/Language/Haskell/TH/Lift.hs +26/−4
- th-lift.cabal +1/−1
Changelog view
@@ -1,3 +1,13 @@+2015-01-18 Mathieu Boespflug <mboes@tweag.net>++ * GHC 8.1 compatibility.++2015-11-19 Mathieu Boespflug <mboes@tweag.net>++ * Added makeLift, for cases when it's necessary to write the+ instance manually. (Thanks to Ryan Scott).+ * Support empty datatypes and unboxed types.+ 2014-12-07 Mathieu Boespflug <mboes@tweag.net> * Support GHC 7.9 and hopefully 7.10, thanks to Richard Eisenberg.
src/Language/Haskell/TH/Lift.hs view
@@ -121,17 +121,17 @@ consMatches n [] = [match wildP (normalB e) []] where e = [| errorQExp $(stringE ("Can't lift value of empty datatype " ++ nameBase n)) |]-consMatches _ cons = map doCons cons+consMatches _ cons = concatMap doCons cons -doCons :: Con -> Q Match-doCons (NormalC c sts) = do+doCons :: Con -> [Q Match]+doCons (NormalC c sts) = (:[]) $ do ns <- zipWithM (\_ i -> newName ('x':show (i :: Int))) sts [0..] let con = [| conE c |] args = [ liftVar n t | (n, (_, t)) <- zip ns sts ] e = foldl (\e1 e2 -> [| appE $e1 $e2 |]) con args match (conP c (map varP ns)) (normalB e) [] doCons (RecC c sts) = doCons $ NormalC c [(s, t) | (_, s, t) <- sts]-doCons (InfixC sty1 c sty2) = do+doCons (InfixC sty1 c sty2) = (:[]) $ do x0 <- newName "x0" x1 <- newName "x1" let con = [| conE c |]@@ -140,6 +140,21 @@ e = [| infixApp $left $con $right |] match (infixP (varP x0) c (varP x1)) (normalB e) [] doCons (ForallC _ _ c) = doCons c+#if MIN_VERSION_template_haskell(2,11,0)+-- GADTs can have multiple constructor names, when they are written like:+--+-- data T where+-- MkT1, MkT2 :: T+doCons (GadtC cs sts _) = map (\c -> do+ ns <- zipWithM (\_ i -> newName ('x':show (i :: Int))) sts [0..]+ let con = [| conE c |]+ args = [ liftVar n t | (n, (_, t)) <- zip ns sts ]+ e = foldl (\e1 e2 -> [| appE $e1 $e2 |]) con args+ match (conP c (map varP ns)) (normalB e) []+ ) cs+doCons (RecGadtC cs sts _) =+ concatMap (\c -> doCons $ NormalC c [(s,t) | (_, s, t) <- sts]) cs+#endif liftVar :: Name -> Type -> Q Exp liftVar varName (ConT tyName)@@ -169,10 +184,17 @@ #endif -> Q a withInfo i f = case i of+#if MIN_VERSION_template_haskell(2,11,0)+ TyConI (DataD dcx n vsk _ cons _) ->+ f dcx n (map unTyVarBndr vsk) cons+ TyConI (NewtypeD dcx n vsk _ con _) ->+ f dcx n (map unTyVarBndr vsk) [con]+#else TyConI (DataD dcx n vsk cons _) -> f dcx n (map unTyVarBndr vsk) cons TyConI (NewtypeD dcx n vsk con _) -> f dcx n (map unTyVarBndr vsk) [con]+#endif _ -> error (modName ++ ".deriveLift: unhandled: " ++ pprint i) where #if MIN_VERSION_template_haskell(2,8,0)
th-lift.cabal view
@@ -1,5 +1,5 @@ Name: th-lift-Version: 0.7.5+Version: 0.7.6 Cabal-Version: >= 1.8 License: BSD3 License-Files: COPYING, BSD3, GPL-2