linear-generics 0.2.2 → 0.2.3
raw patch · 4 files changed
+36/−16 lines, 4 filesdep ~containersdep ~template-haskelldep ~th-abstractionnew-uploader
Dependency ranges changed: containers, template-haskell, th-abstraction
Files
- CHANGELOG.md +5/−0
- linear-generics.cabal +4/−3
- src/Generics/Linear/TH/Internal.hs +25/−10
- tests/Generics/Deriving/Enum.hs +2/−3
CHANGELOG.md view
@@ -1,3 +1,8 @@+# next [????.??.??]++# 0.2.3+* Support building with `template-haskell-2.21.*` (GHC 9.8).+ # 0.2.2 * Produce an orderly error message if someone gives us `type data`. * Produce an error message much more eagerly when someone tries to
linear-generics.cabal view
@@ -1,5 +1,5 @@ name: linear-generics-version: 0.2.2+version: 0.2.3 synopsis: Generic programming library for generalised deriving. description: This package offers a version of@@ -69,6 +69,7 @@ , GHC == 9.2.7 , GHC == 9.4.4 , GHC == 9.6.1+ , GHC == 9.8.1 extra-source-files: CHANGELOG.md , README.md @@ -98,8 +99,8 @@ build-depends: base >= 4.15 && < 5 , containers >= 0.5.9 && < 0.7 , ghc-prim < 1- , template-haskell >= 2.16 && < 2.21- , th-abstraction >= 0.5 && < 0.6+ , template-haskell >= 2.16 && < 2.22+ , th-abstraction >= 0.5 && < 0.7 default-language: Haskell2010 default-extensions: KindSignatures
src/Generics/Linear/TH/Internal.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE BangPatterns #-}+{-# LANGUAGE CPP #-} {-# LANGUAGE LambdaCase #-} {- |@@ -100,7 +101,7 @@ -- | Given a name, check if that name is a type family. If -- so, return a list of its binders.-getTypeFamilyBinders :: Name -> Q (Maybe [TyVarBndr_ ()])+getTypeFamilyBinders :: Name -> Q (Maybe [TyVarBndrVis]) getTypeFamilyBinders tcName = do info <- reify tcName return $ case info of@@ -325,21 +326,28 @@ fail (ns ++ " Could not reify " ++ nameBase name) `recover` reifyDatatype name- variant_ <- case variant of- Datatype -> pure Datatype_- Newtype -> pure Newtype_- -- This isn't total, but the API requires that the data- -- family instance have at least one constructor anyways,- -- so this will always succeed.- DataInstance -> pure $ DataInstance_ (head cons)- NewtypeInstance -> pure $ NewtypeInstance_ (head cons)- TypeData -> fail $ "Cannot derive Generic instances for TypeData " ++ nameBase name+ variant_ <-+ case variant of+ Datatype -> return Datatype_+ Newtype -> return Newtype_+ DataInstance -> return $ DataInstance_ $ headDataFamInstCon parentName cons+ NewtypeInstance -> return $ NewtypeInstance_ $ headDataFamInstCon parentName cons+ TypeData -> fail $ "Cannot derive Generic instances for TypeData " ++ nameBase name checkDataContext parentName ctxt pure (parentName, tys, cons, variant_) where ns :: String ns = "Generics.Linear.TH.reifyDataInfo: " + -- This isn't total, but the API requires that the data family instance have+ -- at least one constructor anyways, so this will always succeed.+ headDataFamInstCon :: Name -> [ConstructorInfo] -> ConstructorInfo+ headDataFamInstCon dataFamName cons =+ case cons of+ con:_ -> con+ [] -> error $ "reified data family instance without a data constructor: "+ ++ nameBase dataFamName+ -- | One cannot derive Generic(1) instance for anything that uses DatatypeContexts, -- so check to make sure the Cxt field of a datatype is null. checkDataContext :: Name -> Cxt -> Q ()@@ -352,3 +360,10 @@ checkExistentialContext conName vars ctxt = unless (null vars && null ctxt) $ fail $ nameBase conName ++ " must be a vanilla data constructor"++#if !(MIN_VERSION_template_haskell(2,21,0)) && !(MIN_VERSION_th_abstraction(0,6,0))+type TyVarBndrVis = TyVarBndrUnit++bndrReq :: ()+bndrReq = ()+#endif
tests/Generics/Deriving/Enum.hs view
@@ -38,6 +38,7 @@ import Control.Applicative (Const, ZipList) import Data.Int+import Data.Maybe (listToMaybe) import Data.Monoid (All, Any, Dual, Product, Sum) import qualified Data.Monoid as Monoid (First, Last) import Data.Word@@ -106,9 +107,7 @@ findIndex :: (a -> Bool) -> [a] -> Maybe Int findIndex p xs = let l = [ i | (y,i) <- zip xs [(0::Int)..], p y]- in if (null l)- then Nothing- else Just (head l)+ in listToMaybe l -------------------------------------------------------------------------------- -- Generic enum