Merge pull request #1223 from erikd/master

yesod-core: Fix for a *very* late change in ghc-8.0 TH api
This commit is contained in:
Michael Snoyman 2016-04-24 08:23:28 +03:00
commit 18993caf3a
6 changed files with 45 additions and 6 deletions

View File

@ -9,7 +9,7 @@ module Yesod.Core.Internal.TH where
import Prelude hiding (exp) import Prelude hiding (exp)
import Yesod.Core.Handler import Yesod.Core.Handler
import Language.Haskell.TH hiding (cxt) import Language.Haskell.TH hiding (cxt, instanceD)
import Language.Haskell.TH.Syntax import Language.Haskell.TH.Syntax
import qualified Network.Wai as W import qualified Network.Wai as W
@ -106,7 +106,7 @@ mkYesodGeneral namestr args isSub f resS = do
case arg of case arg of
Left t -> ( ConT (mkName t):xs, n:ns, cs ) Left t -> ( ConT (mkName t):xs, n:ns, cs )
Right ts -> ( VarT n :xs, ns Right ts -> ( VarT n :xs, ns
, fmap (\t -> , fmap (\t ->
#if MIN_VERSION_template_haskell(2,10,0) #if MIN_VERSION_template_haskell(2,10,0)
AppT (ConT $ mkName t) (VarT n) AppT (ConT $ mkName t) (VarT n)
#else #else
@ -169,7 +169,7 @@ mkDispatchInstance :: Type -- ^ The master site type
mkDispatchInstance master cxt f res = do mkDispatchInstance master cxt f res = do
clause' <- mkDispatchClause (mkMDS f [|yesodRunner|]) res clause' <- mkDispatchClause (mkMDS f [|yesodRunner|]) res
let thisDispatch = FunD 'yesodDispatch [clause'] let thisDispatch = FunD 'yesodDispatch [clause']
return [InstanceD cxt yDispatch [thisDispatch]] return [instanceD cxt yDispatch [thisDispatch]]
where where
yDispatch = ConT ''YesodDispatch `AppT` master yDispatch = ConT ''YesodDispatch `AppT` master
@ -186,3 +186,10 @@ mkYesodSubDispatch res = do
[innerFun] [innerFun]
] ]
return $ LetE [fun] (VarE helper) return $ LetE [fun] (VarE helper)
instanceD :: Cxt -> Type -> [Dec] -> Dec
#if MIN_VERSION_template_haskell(2,11,0)
instanceD = InstanceD Nothing
#else
instanceD = InstanceD
#endif

View File

@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell #-}
module Yesod.Routes.TH.ParseRoute module Yesod.Routes.TH.ParseRoute
( -- ** ParseRoute ( -- ** ParseRoute
@ -27,7 +28,7 @@ mkParseRouteInstance typ ress = do
(map removeMethods ress) (map removeMethods ress)
helper <- newName "helper" helper <- newName "helper"
fixer <- [|(\f x -> f () x) :: (() -> ([Text], [(Text, Text)]) -> Maybe (Route a)) -> ([Text], [(Text, Text)]) -> Maybe (Route a)|] fixer <- [|(\f x -> f () x) :: (() -> ([Text], [(Text, Text)]) -> Maybe (Route a)) -> ([Text], [(Text, Text)]) -> Maybe (Route a)|]
return $ InstanceD [] (ConT ''ParseRoute `AppT` typ) return $ instanceD [] (ConT ''ParseRoute `AppT` typ)
[ FunD 'parseRoute $ return $ Clause [ FunD 'parseRoute $ return $ Clause
[] []
(NormalB $ fixer `AppE` VarE helper) (NormalB $ fixer `AppE` VarE helper)
@ -42,3 +43,10 @@ mkParseRouteInstance typ ress = do
fixDispatch (Methods x _) = Methods x [] fixDispatch (Methods x _) = Methods x []
fixDispatch x = x fixDispatch x = x
instanceD :: Cxt -> Type -> [Dec] -> Dec
#if MIN_VERSION_template_haskell(2,11,0)
instanceD = InstanceD Nothing
#else
instanceD = InstanceD
#endif

View File

@ -158,7 +158,7 @@ mkRenderRouteInstance' cxt typ ress = do
#else #else
let did = DataInstD [] ''Route [typ] cons clazzes let did = DataInstD [] ''Route [typ] cons clazzes
#endif #endif
return $ InstanceD cxt (ConT ''RenderRoute `AppT` typ) return $ instanceD cxt (ConT ''RenderRoute `AppT` typ)
[ did [ did
, FunD (mkName "renderRoute") cls , FunD (mkName "renderRoute") cls
] : decs ] : decs
@ -172,3 +172,10 @@ notStrict = Bang NoSourceUnpackedness NoSourceStrictness
notStrict :: Strict notStrict :: Strict
notStrict = NotStrict notStrict = NotStrict
#endif #endif
instanceD :: Cxt -> Type -> [Dec] -> Dec
#if MIN_VERSION_template_haskell(2,11,0)
instanceD = InstanceD Nothing
#else
instanceD = InstanceD
#endif

View File

@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE RecordWildCards #-}
module Yesod.Routes.TH.RouteAttrs module Yesod.Routes.TH.RouteAttrs
@ -13,7 +14,7 @@ import Data.Text (pack)
mkRouteAttrsInstance :: Type -> [ResourceTree a] -> Q Dec mkRouteAttrsInstance :: Type -> [ResourceTree a] -> Q Dec
mkRouteAttrsInstance typ ress = do mkRouteAttrsInstance typ ress = do
clauses <- mapM (goTree id) ress clauses <- mapM (goTree id) ress
return $ InstanceD [] (ConT ''RouteAttrs `AppT` typ) return $ instanceD [] (ConT ''RouteAttrs `AppT` typ)
[ FunD 'routeAttrs $ concat clauses [ FunD 'routeAttrs $ concat clauses
] ]
@ -36,3 +37,10 @@ goRes front Resource {..} =
[] []
where where
toText s = VarE 'pack `AppE` LitE (StringL s) toText s = VarE 'pack `AppE` LitE (StringL s)
instanceD :: Cxt -> Type -> [Dec] -> Dec
#if MIN_VERSION_template_haskell(2,11,0)
instanceD = InstanceD Nothing
#else
instanceD = InstanceD
#endif

View File

@ -7,6 +7,7 @@
{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-} {-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE CPP #-}
module Hierarchy module Hierarchy
( hierarchy ( hierarchy
, Dispatcher (..) , Dispatcher (..)
@ -124,7 +125,11 @@ do
, mdsUnwrapper = return , mdsUnwrapper = return
} resources } resources
return return
#if MIN_VERSION_template_haskell(2,11,0)
$ InstanceD Nothing
#else
$ InstanceD $ InstanceD
#endif
[] []
(ConT ''Dispatcher (ConT ''Dispatcher
`AppT` ConT ''Hierarchy `AppT` ConT ''Hierarchy

View File

@ -95,7 +95,11 @@ do
, mdsUnwrapper = return , mdsUnwrapper = return
} ress } ress
return return
#if MIN_VERSION_template_haskell(2,11,0)
$ InstanceD Nothing
#else
$ InstanceD $ InstanceD
#endif
[] []
(ConT ''Dispatcher (ConT ''Dispatcher
`AppT` ConT ''MyApp `AppT` ConT ''MyApp