Add compatibility with GHC 8

This commit is contained in:
Dmitry Bushev 2017-09-14 18:44:08 +03:00
parent ec5c15bcbe
commit c43f7f4e9f
8 changed files with 64 additions and 15 deletions

7
ghc-802.yaml Normal file
View File

@ -0,0 +1,7 @@
resolver: lts-9.0
packages:
- .
extra-deps:
- dom-parser-3.0.0

7
ghc-821.yaml Normal file
View File

@ -0,0 +1,7 @@
resolver: nightly-2017-09-14
packages:
- .
extra-deps:
- dom-parser-3.0.0

38
src/Data/THGen/Compat.hs Normal file
View File

@ -0,0 +1,38 @@
{-# LANGUAGE CPP #-}
module Data.THGen.Compat
( dataD
, strictType
, varStrictType
) where
import qualified Language.Haskell.TH as TH
dataD :: TH.Name -> [TH.ConQ] -> [TH.Name] -> TH.DecQ
#if MIN_VERSION_template_haskell(2,12,0)
dataD name cons derivs = TH.dataD (return []) name [] Nothing cons [derivCls]
where
derivCls = TH.derivClause Nothing $ fmap TH.conT derivs
#elif MIN_VERSION_template_haskell(2,11,0)
dataD name cons derivs = TH.dataD (return []) name [] Nothing cons derivCls
where
derivCls = traverse TH.conT derivs
#else
dataD name = TH.dataD (return []) name []
#endif
#if MIN_VERSION_template_haskell(2,11,0)
strictType :: TH.TypeQ -> TH.BangTypeQ
strictType = TH.bangType (TH.bang TH.noSourceUnpackedness TH.sourceStrict)
#else
strictType :: TH.TypeQ -> TH.StrictTypeQ
strictType = TH.strictType TH.isStrict
#endif
#if MIN_VERSION_template_haskell(2,11,0)
varStrictType :: TH.Name -> TH.BangTypeQ -> TH.VarBangTypeQ
varStrictType = TH.varBangType
#else
varStrictType :: TH.Name -> TH.StrictTypeQ -> TH.VarStrictTypeQ
varStrictType = TH.varStrictType
#endif

View File

@ -28,6 +28,7 @@ import Control.Applicative
import Control.Lens (over, _head, (<&>))
import Control.Monad
import qualified Data.Char as C
import Data.THGen.Compat
import qualified Language.Haskell.TH as TH
import qualified Test.QuickCheck as QC
import qualified Text.Read as R
@ -74,11 +75,9 @@ enumGenerate (EnumDesc exh strName strVals) = do
unknownConstr = case exh of
Exhaustive -> []
NonExhaustive ->
[TH.normalC unknownVal [TH.strictType TH.isStrict [t|String|]]]
TH.dataD
(return [])
[TH.normalC unknownVal [strictType [t|String|]]]
dataD
name
[]
(constrs ++ unknownConstr)
([''Eq, ''Ord] ++ if (exh == Exhaustive) then [''Enum, ''Bounded] else [])
showInstDecl <- do

View File

@ -127,6 +127,7 @@ import qualified Data.Char as C
import Data.List.NonEmpty (NonEmpty)
import Data.Maybe (maybeToList, mapMaybe)
import Data.String
import Data.THGen.Compat
import Data.THGen.Enum
import qualified Data.Text as T
import qualified Language.Haskell.TH as TH
@ -329,7 +330,7 @@ isoXmlGenerateRecord (PrefixName strName' strPrefix') descRecordParts = do
XmlFieldPluralRepeated -> [t| [$fieldType] |]
XmlFieldPluralMultiplied -> [t| NonEmpty $fieldType |]
in
TH.varStrictType fName (TH.strictType TH.isStrict fType)
varStrictType fName (strictType fType)
IsoXmlDescRecordAttribute descAttribute ->
let
IsoXmlDescAttribute
@ -339,11 +340,9 @@ isoXmlGenerateRecord (PrefixName strName' strPrefix') descRecordParts = do
XmlAttributePluralMandatory -> attributeType
XmlAttributePluralOptional -> [t| Maybe $attributeType |]
in
TH.varStrictType fName (TH.strictType TH.isStrict fType)
TH.dataD
(return [])
varStrictType fName (strictType fType)
dataD
name
[]
[TH.recC name fields]
[''Eq, ''Show]
lensDecls <- makeFieldOpticsForDec lensRules dataDecl

View File

@ -1,9 +1,7 @@
resolver: lts-6.27
resolver: lts-6.35
packages:
- "."
- .
extra-deps:
- dom-parser-2.0.0
- type-fun-0.0.1
- open-union-0.2.0.0
- dom-parser-3.0.0

View File

@ -1,3 +1,4 @@
{-# OPTIONS -fno-warn-unused-imports #-}
module Main where
import TestDefs

View File

@ -21,7 +21,7 @@ library
exposed-modules: Data.THGen.Enum
Data.THGen.XML
Text.XML.ParentAttributes
other-modules: Data.THGen.Compat
build-depends: QuickCheck >= 2.8
, base >=4.8 && <5
, dom-parser >= 2.0.0