packages feed

proxied 0.2 → 0.3

raw patch · 6 files changed

+133/−69 lines, 6 files

Files

CHANGELOG.md view
@@ -1,3 +1,14 @@+## 0.3+* Update for GHC 8.2+  * Since `typeRep#`, `typeNatTypeRep`, and `typeSymbolTypeRep` are no longer+    exported from `base`, `theTypeRep#`, `theTypeNatTypeRep`, and+    `theTypeSymbolTypeRep` are now synonyms for `theTypeRep`+  * Happily, the new type signature for `GHC.OverloadedLabels.fromLabel` is now+    exactly the same as `theFromLabel`, so the latter is now a synonym for the+    former+* Use explicit kind variable binders in `Data.Proxyless`+* Use explicit `forall`s in `Data.Proxied` for consistency+ ## 0.2 * Added the `Data.Proxyless` module * Added `proxyHashed` to `Data.Proxied`
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2016, Ryan Scott+Copyright (c) 2016-2017, Ryan Scott  All rights reserved. 
README.md view
@@ -19,4 +19,4 @@   `Proxy`, however, does not carry any of the error-throwing risks of `undefined`, so it is much more preferable to take `Proxy` as an argument to a constant function instead of `undefined`. Unfortunately, `Proxy` was included in `base` until GHC 7.8, so many of `base`'s typeclasses still contain constant functions that aren't amenable to passing `Proxy`. `proxied` addresses this issue by providing variants of those typeclass functions that take an explicit `proxy` value. -This library also contains the "Data.Proxyless" module, which works in the opposite direction. That is, one can take functions which take `Proxy` (or `undefined`) as an argument and convert them to functions which take no arguments. This trick relies on the `-XTypeApplications` extension, so it is only available with GHC 8.0 or later.+This library also contains the `Data.Proxyless` module, which works in the opposite direction. That is, one can take functions which take `Proxy` (or `undefined`) as an argument and convert them to functions which take no arguments. This trick relies on the `-XTypeApplications` extension, so it is only available with GHC 8.0 or later.
proxied.cabal view
@@ -1,5 +1,5 @@ name:                proxied-version:             0.2+version:             0.3 synopsis:            Make functions consume Proxy instead of undefined description:         @proxied@ is a simple library that exports a function to                      convert constant functions to ones that take a @proxy@@@ -34,7 +34,7 @@ author:              Ryan Scott maintainer:          Ryan Scott <ryan.gl.scott@gmail.com> stability:           Provisional-copyright:           (C) 2016 Ryan Scott+copyright:           (C) 2016-2017 Ryan Scott category:            Data build-type:          Simple tested-with:         GHC == 7.0.4@@ -43,7 +43,8 @@                    , GHC == 7.6.3                    , GHC == 7.8.4                    , GHC == 7.10.3-                   , GHC == 8.0.1+                   , GHC == 8.0.2+                   , GHC == 8.2.1 extra-source-files:  CHANGELOG.md, README.md cabal-version:       >=1.10 @@ -56,8 +57,10 @@   if impl(ghc >= 8.0)     exposed-modules:   Data.Proxyless   build-depends:       base             >= 4.3    && < 5-                     , generic-deriving >= 1.10.1 && < 2-                     , tagged           >= 0.4.4  && < 1+  if !impl(ghc >= 7.6)+    build-depends:     generic-deriving >= 1.10.1 && < 2+  if !impl(ghc >= 7.8)+    build-depends:     tagged           >= 0.4.4  && < 1   hs-source-dirs:      src   default-language:    Haskell2010   ghc-options:         -Wall
src/Data/Proxied.hs view
@@ -1,6 +1,7 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE MagicHash #-}+{-# LANGUAGE ScopedTypeVariables #-}  #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Trustworthy #-}@@ -14,7 +15,7 @@  {-| Module:      Data.Proxied-Copyright:   (C) 2016 Ryan Scott+Copyright:   (C) 2016-2017 Ryan Scott License:     BSD-style (see the file LICENSE) Maintainer:  Ryan Scott Stability:   Provisional@@ -81,8 +82,12 @@  import Foreign.Storable (Storable(..)) +#if MIN_VERSION_base(4,6,0)+import GHC.Generics+#else import Generics.Deriving.Base import Generics.Deriving.Instances ()+#endif  #if MIN_VERSION_base(4,7,0) import Data.Bits (FiniteBits(..))@@ -93,7 +98,7 @@ -- | Converts a constant function to one that takes a @proxy@ argument. -- -- /Since: 0.1/-proxied :: (a -> b) -> proxy a -> b+proxied :: forall proxy a b. (a -> b) -> proxy a -> b proxied f _ = f undefined  #if MIN_VERSION_base(4,7,0)@@ -101,7 +106,7 @@ -- This function is only available with @base-4.7@ or later. -- -- /Since: 0.2/-proxyHashed :: (a -> b) -> Proxy# a -> b+proxyHashed :: forall a b. (a -> b) -> Proxy# a -> b proxyHashed f _ = f undefined #endif @@ -110,7 +115,7 @@ -- but it's here for symmetry.) -- -- /Since: 0.1/-unproxied :: (Proxy a -> b) -> a -> b+unproxied :: forall a b. (Proxy a -> b) -> a -> b unproxied f _ = f Proxy  -------------------------------------------------------------------------------@@ -120,13 +125,13 @@ -- | @'bitSizeProxied' = 'proxied' 'bitSize'@ -- -- /Since: 0.1/-bitSizeProxied :: Bits a => proxy a -> Int+bitSizeProxied :: forall proxy a. Bits a => proxy a -> Int bitSizeProxied = proxied bitSize  -- | @'isSignedProxied' = 'proxied' 'isSigned'@ -- -- /Since: 0.1/-isSignedProxied :: Bits a => proxy a -> Bool+isSignedProxied :: forall proxy a. Bits a => proxy a -> Bool isSignedProxied = proxied isSigned  #if MIN_VERSION_base(4,7,0)@@ -135,7 +140,7 @@ -- This function is only available with @base-4.7@ or later. -- -- /Since: 0.1/-bitSizeMaybeProxied :: Bits a => proxy a -> Maybe Int+bitSizeMaybeProxied :: forall proxy a. Bits a => proxy a -> Maybe Int bitSizeMaybeProxied = proxied bitSizeMaybe  -- | @'finiteBitSizeProxied' = 'proxied' 'finiteBitSize'@@@ -143,7 +148,7 @@ -- This function is only available with @base-4.7@ or later. -- -- /Since: 0.1/-finiteBitSizeProxied :: FiniteBits a => proxy a -> Int+finiteBitSizeProxied :: forall proxy a. FiniteBits a => proxy a -> Int finiteBitSizeProxied = proxied finiteBitSize #endif @@ -154,7 +159,7 @@ -- | @'dataTypeOfProxied' = 'proxied' 'dataTypeOf'@ -- -- /Since: 0.1/-dataTypeOfProxied :: Data a => proxy a -> DataType+dataTypeOfProxied :: forall proxy a. Data a => proxy a -> DataType dataTypeOfProxied = proxied dataTypeOf  -------------------------------------------------------------------------------@@ -166,8 +171,14 @@ -- On @base-4.7@ and later, this is identical to 'typeRep'. -- -- /Since: 0.1/-typeOfProxied :: Typeable a => proxy a -> TypeRep+typeOfProxied :: forall proxy #if MIN_VERSION_base(4,7,0)+                        (a :: k)+#else+                        a+#endif+                        . Typeable a => proxy a -> TypeRep+#if MIN_VERSION_base(4,7,0) typeOfProxied = typeRep #else typeOfProxied = proxied typeOf@@ -180,29 +191,33 @@ -- | @'sizeOfProxied' = 'proxied' 'sizeOf'@ -- -- /Since: 0.1/-sizeOfProxied :: Storable a => proxy a -> Int+sizeOfProxied :: forall proxy a. Storable a => proxy a -> Int sizeOfProxied = proxied sizeOf  -- | @'alignmentProxied' = 'proxied' 'alignment'@ -- -- /Since: 0.1/-alignmentProxied :: Storable a => proxy a -> Int+alignmentProxied :: forall proxy a. Storable a => proxy a -> Int alignmentProxied = proxied alignment  ------------------------------------------------------------------------------- -- GHC.Generics ------------------------------------------------------------------------------- -#if MIN_VERSION_base(4,9,0)-# define T_TYPE(t) (t :: k -> (* -> *) -> * -> *)+#define GENERIC_FORALL(t,letter) forall proxy T_TYPE(t) letter f a++#if MIN_VERSION_base(4,10,0)+# define T_TYPE(t) (t :: k1 -> (k2 -> *) -> k2 -> *)+#elif MIN_VERSION_base(4,9,0)+# define T_TYPE(t) (t :: k1 -> (*  -> *) -> k2 -> *) #else-# define T_TYPE(t) (t :: * -> (* -> *) -> * -> *)+# define T_TYPE(t) (t :: *  -> (*  -> *) -> *  -> *) #endif  -- | @'datatypeNameProxied' = 'proxied' 'datatypeName'@ -- -- /Since: 0.1/-datatypeNameProxied :: Datatype d+datatypeNameProxied :: GENERIC_FORALL(t,d). Datatype d                     => proxy (T_TYPE(t) d f a)                     -> [Char] datatypeNameProxied = proxied datatypeName@@ -210,7 +225,7 @@ -- | @'moduleNameProxied' = 'proxied' 'moduleName'@ -- -- /Since: 0.1/-moduleNameProxied :: Datatype d+moduleNameProxied :: GENERIC_FORALL(t,d). Datatype d                   => proxy (T_TYPE(t) d f a)                   -> [Char] moduleNameProxied = proxied moduleName@@ -221,7 +236,7 @@ -- This function is only available with @base-4.7@ or later. -- -- /Since: 0.1/-isNewtypeProxied :: Datatype d+isNewtypeProxied :: GENERIC_FORALL(t,d). Datatype d                  => proxy (T_TYPE(t) d f a)                  -> Bool isNewtypeProxied = proxied isNewtype@@ -233,7 +248,7 @@ -- This function is only avaiable with @base-4.9@ or later. -- -- /Since: 0.1/-packageNameProxied :: Datatype d+packageNameProxied :: GENERIC_FORALL(t,d). Datatype d                    => proxy (T_TYPE(t) d f a)                    -> [Char] packageNameProxied = proxied packageName@@ -242,7 +257,7 @@ -- | @'conNameProxied' = 'proxied' 'conName'@ -- -- /Since: 0.1/-conNameProxied :: Constructor c+conNameProxied :: GENERIC_FORALL(t,c). Constructor c                => proxy (T_TYPE(t) c f a)                -> [Char] conNameProxied = proxied conName@@ -250,7 +265,7 @@ -- | @'conFixityProxied' = 'proxied' 'conFixity'@ -- -- /Since: 0.1/-conFixityProxied :: Constructor c+conFixityProxied :: GENERIC_FORALL(t,c). Constructor c                  => proxy (T_TYPE(t) c f a)                  -> Fixity conFixityProxied = proxied conFixity@@ -258,7 +273,7 @@ -- | @'conIsRecordProxied' = 'proxied' 'conIsRecord'@ -- -- /Since: 0.1/-conIsRecordProxied :: Constructor c+conIsRecordProxied :: GENERIC_FORALL(t,c). Constructor c                    => proxy (T_TYPE(t) c f a)                    -> Bool conIsRecordProxied = proxied conIsRecord@@ -266,7 +281,7 @@ -- | @'selNameProxied' = 'proxied' 'selName'@ -- -- /Since: 0.1/-selNameProxied :: Selector s+selNameProxied :: GENERIC_FORALL(t,s). Selector s                => proxy (T_TYPE(t) s f a)                -> [Char] selNameProxied = proxied selName@@ -277,7 +292,7 @@ -- This function is only available with @base-4.9@ or later. -- -- /Since: 0.1/-selSourceUnpackednessProxied :: Selector s+selSourceUnpackednessProxied :: GENERIC_FORALL(t,s). Selector s                              => proxy (T_TYPE(t) s f a)                              -> SourceUnpackedness selSourceUnpackednessProxied = proxied selSourceUnpackedness@@ -287,7 +302,7 @@ -- This function is only available with @base-4.9@ or later. -- -- /Since: 0.1/-selSourceStrictnessProxied :: Selector s+selSourceStrictnessProxied :: GENERIC_FORALL(t,s). Selector s                            => proxy (T_TYPE(t) s f a)                            -> SourceStrictness selSourceStrictnessProxied = proxied selSourceStrictness@@ -297,7 +312,7 @@ -- This function is only available with @base-4.9@ or later. -- -- /Since: 0.1/-selDecidedStrictnessProxied :: Selector s+selDecidedStrictnessProxied :: GENERIC_FORALL(t,s). Selector s                             => proxy (T_TYPE(t) s f a)                             -> DecidedStrictness selDecidedStrictnessProxied = proxied selDecidedStrictness@@ -310,19 +325,19 @@ -- | @'floatRadixProxied' = 'proxied' 'floatRadix'@ -- -- /Since: 0.1/-floatRadixProxied :: RealFloat a => proxy a -> Integer+floatRadixProxied :: forall proxy a. RealFloat a => proxy a -> Integer floatRadixProxied = proxied floatRadix  -- | @'floatDigitsProxied' = 'proxied' 'floatDigits'@ -- -- /Since: 0.1/-floatDigitsProxied :: RealFloat a => proxy a -> Int+floatDigitsProxied :: forall proxy a. RealFloat a => proxy a -> Int floatDigitsProxied = proxied floatDigits  -- | @'floatRangeProxied' = 'proxied' 'floatRange'@ -- -- /Since: 0.1/-floatRangeProxied :: RealFloat a => proxy a -> (Int, Int)+floatRangeProxied :: forall proxy a. RealFloat a => proxy a -> (Int, Int) floatRangeProxied = proxied floatRange  -------------------------------------------------------------------------------@@ -335,6 +350,6 @@ -- This function is only available with @base-4.7@ or later. -- -- /Since: 0.1/-parseFormatProxied :: PrintfArg a => proxy a -> ModifierParser+parseFormatProxied :: forall proxy a. PrintfArg a => proxy a -> ModifierParser parseFormatProxied = proxied parseFormat #endif
src/Data/Proxyless.hs view
@@ -1,19 +1,23 @@ {-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE CPP #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE Trustworthy #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-}+{-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeOperators #-} -{-# LANGUAGE ViewPatterns #-}- {-# OPTIONS_GHC -Wno-deprecations #-}++#if __GLASGOW_HASKELL__ == 800 \+    && __GLASGOW_HASKELL_PATCHLEVEL1__ == 1 {-# OPTIONS_GHC -Wno-type-defaults #-} -- Needed due to GHC Trac #11947+#endif  {-| Module:      Data.Proxyless-Copyright:   (C) 2016 Ryan Scott+Copyright:   (C) 2016-2017 Ryan Scott License:     BSD-style (see the file LICENSE) Maintainer:  Ryan Scott Stability:   Provisional@@ -80,10 +84,13 @@     ) where  import Data.Bits (Bits(..), FiniteBits(..))-import Data.Data hiding (Fixity)+import Data.Data (Data(dataTypeOf), DataType) import Data.Proxy (Proxy(..)) import Data.Type.Equality ((:~:))-import Data.Typeable.Internal (Typeable(..), typeNatTypeRep, typeSymbolTypeRep)+import Data.Typeable (Typeable, TypeRep, typeRep)+#if !(MIN_VERSION_base(4,10,0))+import Data.Typeable.Internal (typeRep#, typeNatTypeRep, typeSymbolTypeRep)+#endif  import Foreign.Storable (Storable(..)) @@ -98,14 +105,14 @@ -- doesn't require an argument. -- -- /Since: 0.2/-proxyless :: forall a b. (Proxy a -> b) -> b+proxyless :: forall k (a :: k) b. (Proxy a -> b) -> b proxyless f = f Proxy  -- | Converts a constant function that takes a 'Proxy#' argument to one that -- doesn't require an argument. -- -- /Since: 0.2/-proxyHashless :: forall a b. (Proxy# a -> b) -> b+proxyHashless :: forall k (a :: k) b. (Proxy# a -> b) -> b proxyHashless f = f proxy#  -- | Converts a constant function that takes an 'undefined' argument to one that@@ -159,27 +166,48 @@  -- | @'theTypeNatTypeRep' = 'proxyHashless' 'typeNatTypeRep'@ --+-- Note that in @base-4.10@ and later, 'theTypeNatTypeRep' is simply a synonym+-- for 'theTypeRep', as 'typeNatTypeRep' is no longer exported.+-- -- /Since: 0.2/ theTypeNatTypeRep :: forall a. KnownNat a => TypeRep-theTypeNatTypeRep = proxyHashless @a typeNatTypeRep+#if MIN_VERSION_base(4,10,0)+theTypeNatTypeRep = theTypeRep @_ @a+#else+theTypeNatTypeRep = proxyHashless @_ @a typeNatTypeRep+#endif  -- | @'theTypeRep' = 'proxyless' 'typeRep'@ -- -- /Since: 0.2/-theTypeRep :: forall a. Typeable a => TypeRep-theTypeRep = proxyless @a typeRep+theTypeRep :: forall k (a :: k). Typeable a => TypeRep+theTypeRep = proxyless @_ @a typeRep  -- | @'theTypeRep#' = 'proxyHashless' 'typeRep#'@ --+-- Note that in @base-4.10@ and later, 'theTypeRep#' is simply a synonym for+-- 'theTypeRep', as 'typeRep#' is no longer exported.+-- -- /Since: 0.2/-theTypeRep# :: forall a. Typeable a => TypeRep-theTypeRep# = proxyHashless @a typeRep#+theTypeRep# :: forall k (a :: k). Typeable a => TypeRep+#if MIN_VERSION_base(4,10,0)+theTypeRep# = theTypeRep @k @a+#else+theTypeRep# = proxyHashless @_ @a typeRep#+#endif  -- | @'theTypeSymbolTypeRep' = 'proxyHashless' 'typeSymbolTypeRep'@ --+-- Note that in @base-4.10@ and later, 'theTypeSymbolTypeRep' is simply a+-- synonym for 'theTypeRep', as 'typeSymbolTypeRep' is no longer exported.+-- -- /Since: 0.2/ theTypeSymbolTypeRep :: forall a. KnownSymbol a => TypeRep-theTypeSymbolTypeRep = proxyHashless @a typeSymbolTypeRep+#if MIN_VERSION_base(4,10,0)+theTypeSymbolTypeRep = theTypeRep @_ @a+#else+theTypeSymbolTypeRep = proxyHashless @_ @a typeSymbolTypeRep+#endif  ------------------------------------------------------------------------------- -- Foreign.Storable@@ -204,78 +232,85 @@ -- | @'theDatatypeName' = 'datatypeName' 'undefined'@ -- -- /Since: 0.2/-theDatatypeName :: forall d. Datatype d => [Char]+theDatatypeName :: forall k (d :: k). Datatype d => [Char] theDatatypeName = datatypeName @d undefined  -- | @'theModuleName' = 'moduleName' 'undefined'@ -- -- /Since: 0.2/-theModuleName :: forall d. Datatype d => [Char]+theModuleName :: forall k (d :: k). Datatype d => [Char] theModuleName = moduleName @d undefined  -- | @'theIsNewtype' = 'isNewtype' 'undefined'@ -- -- /Since: 0.2/-theIsNewtype :: forall d. Datatype d => Bool+theIsNewtype :: forall k (d :: k). Datatype d => Bool theIsNewtype = isNewtype @d undefined  -- | @'thePackageName' = 'packageName' 'undefined'@ -- -- /Since: 0.2/-thePackageName :: forall d. Datatype d => [Char]+thePackageName :: forall k (d :: k). Datatype d => [Char] thePackageName = packageName @d undefined  -- | @'theConName' = 'conName' 'undefined'@ -- -- /Since: 0.2/-theConName :: forall c. Constructor c => [Char]+theConName :: forall k (c :: k). Constructor c => [Char] theConName = conName @c undefined  -- | @'theConFixity' = 'conFixity' 'undefined'@ -- -- /Since: 0.2/-theConFixity :: forall c. Constructor c => Fixity+theConFixity :: forall k (c :: k). Constructor c => Fixity theConFixity = conFixity @c undefined  -- | @'theConIsRecord' = 'conIsRecord' 'undefined'@ -- -- /Since: 0.2/-theConIsRecord :: forall c. Constructor c => Bool+theConIsRecord :: forall k (c :: k). Constructor c => Bool theConIsRecord = conIsRecord @c undefined  -- | @'theSelName' = 'selName' 'undefined'@ -- -- /Since: 0.2/-theSelName :: forall s. Selector s => [Char]+theSelName :: forall k (s :: k). Selector s => [Char] theSelName = selName @s undefined  -- | @'theSelSourceUnpackedness' = 'selSourceUnpackedness' 'undefined'@ -- -- /Since: 0.2/-theSelSourceUnpackedness :: forall s. Selector s => SourceUnpackedness+theSelSourceUnpackedness :: forall k (s :: k). Selector s => SourceUnpackedness theSelSourceUnpackedness = selSourceUnpackedness @s undefined  -- | @'theSelSourceStrictness' = 'selSourceStrictness' 'undefined'@ -- -- /Since: 0.2/-theSelSourceStrictness :: forall s. Selector s => SourceStrictness+theSelSourceStrictness :: forall k (s :: k). Selector s => SourceStrictness theSelSourceStrictness = selSourceStrictness @s undefined  -- | @'theSelDecidedStrictness' = 'selDecidedStrictness' 'undefined'@ -- -- /Since: 0.2/-theSelDecidedStrictness :: forall s. Selector s => DecidedStrictness+theSelDecidedStrictness :: forall k (s :: k). Selector s => DecidedStrictness theSelDecidedStrictness = selDecidedStrictness @s undefined  ------------------------------------------------------------------------------- -- GHC.Generics ------------------------------------------------------------------------------- --- | @'theFromLabel' = 'proxyHashless' 'fromLabel'@+-- | In @base-4.10@ and later, this is simply a synonym for 'fromLabel'.+-- In @base-4.9@, 'theFromLabel' is defined as: --+-- @'theFromLabel' = 'proxyHashless' 'fromLabel'@+-- -- /Since: 0.2/ theFromLabel :: forall x a. IsLabel x a => a-theFromLabel = proxyHashless @x fromLabel+#if MIN_VERSION_base(4,10,0)+theFromLabel = fromLabel @x+#else+theFromLabel = proxyHashless @_ @x fromLabel+#endif  ------------------------------------------------------------------------------- -- GHC.TypeLits@@ -285,13 +320,13 @@ -- -- /Since: 0.2/ theNatVal :: forall n. KnownNat n => Integer-theNatVal = proxyless @n natVal+theNatVal = proxyless @_ @n natVal  -- | @`theNatVal'` = 'proxyHashless' `natVal'`@ -- -- /Since: 0.2/ theNatVal' :: forall n. KnownNat n => Integer-theNatVal' = proxyHashless @n natVal'+theNatVal' = proxyHashless @_ @n natVal'  -- | @'theSameNat' = 'sameNat' 'Proxy' 'Proxy'@ --@@ -309,25 +344,25 @@ -- -- /Since: 0.2/ theSomeNat :: forall n. KnownNat n => SomeNat-theSomeNat = proxyless @n SomeNat+theSomeNat = proxyless @_ @n SomeNat  -- | @'theSomeSymbol' = 'proxyless' 'SomeSymbol'@ -- -- /Since: 0.2/ theSomeSymbol :: forall n. KnownSymbol n => SomeSymbol-theSomeSymbol = proxyless @n SomeSymbol+theSomeSymbol = proxyless @_ @n SomeSymbol  -- | @'theSymbolVal' = 'proxyless' 'symbolVal'@ -- -- /Since: 0.2/ theSymbolVal :: forall n. KnownSymbol n => String-theSymbolVal = proxyless @n symbolVal+theSymbolVal = proxyless @_ @n symbolVal  -- | @`theSymbolVal'` = 'proxyHashless' `symbolVal'`@ -- -- /Since: 0.2/ theSymbolVal' :: forall n. KnownSymbol n => String-theSymbolVal' = proxyHashless @n symbolVal'+theSymbolVal' = proxyHashless @_ @n symbolVal'  ------------------------------------------------------------------------------- -- Prelude