OneTuple 0.3 → 0.3.1
raw patch · 6 files changed
+98/−20 lines, 6 filesdep +hashabledep +template-haskelldep ~basedep ~semigroupsdep ~transformers-compatPVP ok
version bump matches the API change (PVP)
Dependencies added: hashable, template-haskell
Dependency ranges changed: base, semigroups, transformers-compat
API changes (from Hackage documentation)
+ Data.Tuple.Solo: instance Data.Hashable.Class.Hashable a => Data.Hashable.Class.Hashable (Data.Tuple.Solo.Solo a)
+ Data.Tuple.Solo: instance Data.Hashable.Class.Hashable1 Data.Tuple.Solo.Solo
+ Data.Tuple.Solo.TH: tupE :: Monad m => [m Exp] -> m Exp
Files
- Changelog.md +6/−0
- OneTuple.cabal +20/−5
- src/Data/Tuple/Solo.hs +15/−15
- src/Data/Tuple/Solo/TH.hs +44/−0
- test/instances.hs +5/−0
- test/th.hs +8/−0
Changelog.md view
@@ -1,3 +1,9 @@+# 0.3.1++- Add `Data.Tuple.Solo.TH` with `tupE` using `Solo` from this package+- Add `Hashable` and `Hashable1` instances+- Drop GHC-7.0 and GHC-7.2 support+ # 0.3 - Rename `OneTuple` to `Solo`
OneTuple.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: OneTuple-version: 0.3+version: 0.3.1 synopsis: Singleton Tuple category: Data description:@@ -22,9 +22,7 @@ stability: experimental build-type: Simple tested-with:- GHC ==7.0.4- || ==7.2.2- || ==7.4.2+ GHC ==7.4.2 || ==7.6.3 || ==7.8.4 || ==7.10.3@@ -48,13 +46,19 @@ exposed-modules: Data.Tuple.OneTuple Data.Tuple.Solo+ Data.Tuple.Solo.TH hs-source-dirs: src- build-depends: base >=4.3 && <4.17+ build-depends:+ base >=4.5 && <4.17+ , template-haskell if impl(ghc >=9.0) build-depends: ghc-prim + else+ build-depends: hashable >=1.3.5.0 && <1.5+ if !impl(ghc >=8.0) build-depends: semigroups >=0.18.4 && <0.20@@ -80,6 +84,7 @@ main-is: instances.hs build-depends: base+ , hashable >=1.3.5.0 && <1.5 , OneTuple if !impl(ghc >=8.0)@@ -87,3 +92,13 @@ semigroups , transformers , transformers-compat++test-suite th+ type: exitcode-stdio-1.0+ default-language: Haskell98+ hs-source-dirs: test+ main-is: th.hs+ build-depends:+ base+ , OneTuple+ , template-haskell
src/Data/Tuple/Solo.hs view
@@ -1,13 +1,7 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE DeriveDataTypeable #-}-#if __GLASGOW_HASKELL__ >= 704 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 702-{-# LANGUAGE Trustworthy #-}-#endif-#if __GLASGOW_HASKELL__ >=702 {-# LANGUAGE DeriveGeneric #-}-#endif -- | 'Solo' fills the /tuple gap/ with a singleton tuple. --@@ -74,6 +68,11 @@ import Data.Functor.Classes (Eq1 (..), Ord1 (..), Show1 (..), Read1 (..)) +#if !(MIN_VERSION_base(4,15,0))+import Data.Hashable (Hashable (..))+import Data.Hashable.Lifted (Hashable1 (..), hashWithSalt1)+#endif+ #if LIFTED_FUNCTOR_CLASSES #if MIN_VERSION_base(4,10,0) import Data.Functor.Classes (readData, readUnaryWith, liftReadListDefault, liftReadListPrecDefault)@@ -82,24 +81,17 @@ #endif #endif -#if MIN_VERSION_base(4,4,0) import GHC.Generics (Generic, Generic1)-#endif--#if MIN_VERSION_base(4,4,0) import Control.Monad.Zip (MonadZip (..))-#endif -- | Solo is the singleton tuple data type. data Solo a = Solo { getSolo :: a } deriving ( Eq,Ord,Bounded,Read,Typeable,Data-#if MIN_VERSION_base(4,4,0) , Generic #if __GLASGOW_HASKELL__ >=706 , Generic1 #endif-#endif ) instance Show a => Show (Solo a) where@@ -172,10 +164,8 @@ instance MonadFix Solo where mfix f = let a = f (getSolo a) in a -#if MIN_VERSION_base(4,4,0) instance MonadZip Solo where mzipWith f (Solo a) (Solo b) = Solo (f a b)-#endif #ifdef LIFTED_FUNCTOR_CLASSES instance Eq1 Solo where@@ -205,4 +195,14 @@ instance Show1 Solo where showsPrec1 = showsPrec #endif +#endif++#if !(MIN_VERSION_base(4,15,0))+-- | @since 0.3.1+instance Hashable a => Hashable (Solo a) where+ hashWithSalt = hashWithSalt1++-- | @since 0.3.1+instance Hashable1 Solo where+ liftHashWithSalt h salt (Solo a) = h salt a #endif
+ src/Data/Tuple/Solo/TH.hs view
@@ -0,0 +1,44 @@+{-# LANGUAGE CPP #-}+#if __GLASGOW_HASKELL__ >= 800+{-# LANGUAGE TemplateHaskellQuotes #-}+#endif+-- | This module provides TH helpers,+-- which use 'Solo' from this package, for 1-tuples.+module Data.Tuple.Solo.TH (+ tupE,+) where+++#if MIN_VERSION_template_haskell(2,17,0)+import Language.Haskell.TH (tupE)+#else+import Data.Tuple.Solo++import qualified Language.Haskell.TH as TH+import qualified Language.Haskell.TH.Syntax as TH++makeTup :: [TH.Exp] -> TH.Exp+makeTup [x] = TH.AppE (TH.ConE soloConName) x+#if MIN_VERSION_template_haskell(2,16,0)+makeTup xs = TH.TupE (map Just xs)+#else+makeTup xs = TH.TupE xs+#endif++soloConName :: TH.Name+#if __GLASGOW_HASKELL__ >= 800+soloConName = 'Solo+#else+#ifndef CURRENT_PACKAGE_KEY +#error "CURRENT_PACKAGE_KEY undefined"+#endif++soloConName = TH.mkNameG_d CURRENT_PACKAGE_KEY "Data.Tuple.Solo" "Solo"+#endif++tupE :: Monad m => [m TH.Exp] -> m TH.Exp+tupE xs = do+ xs' <- sequence xs+ return (makeTup xs')+#endif+
test/instances.hs view
@@ -6,6 +6,8 @@ import Data.Data (Data) import Data.Foldable (Foldable (..)) import Data.Functor.Classes (Eq1, Ord1, Read1, Show1)+import Data.Hashable (Hashable)+import Data.Hashable.Lifted (Hashable1) import Data.Ix (Ix) import Data.Monoid (Monoid (..)) import Data.Semigroup (Semigroup (..))@@ -58,3 +60,6 @@ hasOrd1 :: Ord1 f => f a -> f a; hasOrd1 x = x; testOrd1 = hasOrd1 tup1 hasShow1 :: Show1 f => f a -> f a; hasShow1 x = x; testShow1 = hasShow1 tup1 hasRead1 :: Read1 f => f a -> f a; hasRead1 x = x; testRead1 = hasRead1 tup1++hasHashable :: Hashable a => a -> a; hasHashable x = x; testHashable = hasHashable tup1+hasHashable1 :: Hashable1 f => f a -> f a; hasHashable1 x = x; testHashable1 = hasHashable1 tup1
+ test/th.hs view
@@ -0,0 +1,8 @@+{-# LANGUAGE TemplateHaskell #-}+module Main where++import Data.Tuple.Solo+import Data.Tuple.Solo.TH (tupE)++main :: IO ()+main = print $ Solo 'x' == $(tupE [[| 'x' |]])