Skip to content

Commit

Permalink
initial set of changes for ghc-8
Browse files Browse the repository at this point in the history
  • Loading branch information
jwaldmann committed Mar 18, 2016
1 parent 7e98df6 commit 0f4178e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/dist/
*.o
*.hi
*~
12 changes: 12 additions & 0 deletions Language/Haskell/Convert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ instance Convert a b => Convert [a] [b] where

instance Convert TH.Dec HS.Decl where
conv x = case x of
#if MIN_VERSION_template_haskell(2,11,0)
DataD cxt n vs _ con ds -> f DataType cxt n vs con ds
NewtypeD cxt n vs _ con ds -> f NewType cxt n vs [con] ds
#else
DataD cxt n vs con ds -> f DataType cxt n vs con ds
NewtypeD cxt n vs con ds -> f NewType cxt n vs [con] ds
#endif
where
f :: DataOrNew -> Cxt -> TH.Name -> [TyVarBndr] -> [Con] -> [TH.Name] -> HS.Decl
f t cxt n vs con ds = DataDecl sl t (c cxt) (c n) (c vs) (c con) []
Expand All @@ -63,11 +68,18 @@ instance Convert TH.Con HS.ConDecl where
conv (InfixC x n y) = InfixConDecl (c x) (c n) (c y)

instance Convert TH.StrictType HS.Type where
#if MIN_VERSION_template_haskell(2,11,0)
conv (Bang SourceUnpack SourceStrict, x) = TyBang UnpackedTy $ TyBang BangedTy $ c x
conv (Bang SourceUnpack NoSourceStrictness, x) = TyBang UnpackedTy $ c x
conv (Bang NoSourceUnpackedness SourceStrict, x) = TyBang BangedTy $ c x
conv (Bang NoSourceUnpackedness NoSourceStrictness, x) = c x
#else
conv (IsStrict, x) = TyBang BangedTy $ c x
conv (NotStrict, x) = c x
#if __GLASGOW_HASKELL__ >= 704
conv (Unpacked, x) = TyBang UnpackedTy $ c x
#endif
#endif

instance Convert TH.Type HS.Type where
conv (ForallT xs cxt t) = TyForall (Just $ c xs) (c cxt) (c t)
Expand Down
8 changes: 8 additions & 0 deletions Language/Haskell/TH/Compat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@ fromTyVar v = v


dataDefinitionTypeArgs :: Dec -> [Name]
#if MIN_VERSION_template_haskell(2,11,0)
dataDefinitionTypeArgs (DataD _cx name _ _ _ cxt) = map from_cxt cxt
dataDefinitionTypeArgs (NewtypeD cx name _ _ _ cxt) = map from_cxt cxt
#else
#if __GLASGOW_HASKELL__ >= 612
dataDefinitionTypeArgs (DataD _cx name _ _ args) = args
dataDefinitionTypeArgs (NewtypeD cx name _ _ args) = args
#else
dataDefinitionTypeArgs (DataD _cx name args cons _derv) = args
dataDefinitionTypeArgs (NewtypeD cx name args con derv) = args
#endif
#endif

from_cxt :: Type -> Name
from_cxt (ConT name) = name

#if __GLASGOW_HASKELL__ >= 612 && __GLASGOW_HASKELL__ < 709
typeToPred :: Type -> Pred
Expand Down
23 changes: 23 additions & 0 deletions Language/Haskell/TH/Data.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
-- | The core module of the Data.Derive system. This module contains
-- the data types used for communication between the extractors and
-- the derivors.

{-# language CPP #-}

module Language.Haskell.TH.Data where

import Data.Char
Expand All @@ -18,24 +21,44 @@ type CtorDef = Con


dataName :: DataDef -> String
#if MIN_VERSION_template_haskell(2,11,0)
dataName (DataD _ name _ _ _ _) = unqualifiedName name
dataName (NewtypeD _ name _ _ _ _) = unqualifiedName name
#else
dataName (DataD _ name _ _ _) = unqualifiedName name
dataName (NewtypeD _ name _ _ _) = unqualifiedName name
#endif

qualifiedDataName :: DataDef -> Name
#if MIN_VERSION_template_haskell(2,11,0)
qualifiedDataName (DataD _ name _ _ _ _) = name
qualifiedDataName (NewtypeD _ name _ _ _ _) = name
#else
qualifiedDataName (DataD _ name _ _ _) = name
qualifiedDataName (NewtypeD _ name _ _ _) = name
#endif

dataArity :: DataDef -> Int
#if MIN_VERSION_template_haskell(2,11,0)
dataArity (DataD _ _ xs _ _ _) = length xs
dataArity (NewtypeD _ _ xs _ _ _) = length xs
#else
dataArity (DataD _ _ xs _ _) = length xs
dataArity (NewtypeD _ _ xs _ _) = length xs
#endif

dataArgs :: DataDef -> [Name]
dataArgs = dataDefinitionTypeArgs


dataCtors :: DataDef -> [CtorDef]
#if MIN_VERSION_template_haskell(2,11,0)
dataCtors (DataD _ _ _ _ xs _) = xs
dataCtors (NewtypeD _ _ _ _ x _) = [x]
#else
dataCtors (DataD _ _ _ xs _) = xs
dataCtors (NewtypeD _ _ _ x _) = [x]
#endif


ctorName :: CtorDef -> String
Expand Down

0 comments on commit 0f4178e

Please sign in to comment.