packages feed

newtype 0.2.1.0 → 0.2.2.0

raw patch · 4 files changed

+51/−2 lines, 4 filesdep ~basesetup-changed

Dependency ranges changed: base

Files

CHANGES.md view
@@ -1,5 +1,10 @@ See also https://pvp.haskell.org/faq +## 0.2.2.0 *(minor)*++ - Provide safe `Coercible`-based default-methods for `pack`/`unpack`+   ([#1](https://github.com/haskell-hvr/newtype/pull/1))+ ## 0.2.1.0 *(minor)*   - Added `Newtype` instances for
Control/Newtype.hs view
@@ -3,6 +3,9 @@ {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE MultiParamTypeClasses  #-} {-# LANGUAGE TypeFamilies           #-}+#if __GLASGOW_HASKELL__ >= 704+{-# LANGUAGE DefaultSignatures      #-}+#endif  {-# OPTIONS_GHC -fno-warn-unused-imports #-} @@ -48,14 +51,50 @@ #if !MIN_VERSION_base(4,7,0) -- necessary evil for 'Newtype Fixed' import           Unsafe.Coerce         (unsafeCoerce)+#else+import           Data.Coerce #endif  -- | Given a @newtype@ @n@, we will always have the same unwrapped type @o@, meaning we can represent this with a fundep @n -> o@. -- -- Any instance of this class just needs to let 'pack' equal to the newtype's constructor, and let 'unpack' destruct the @newtype@ with pattern matching.+--+-- Starting with @newtype-0.2.2.0@, default method implementations are provided using "Data.Coerce" for GHC 7.8 (i.e. @base-4.7.0.0@) and later, i.e.:+--+-- @+-- 'pack'   = 'coerce'+-- 'unpack' = 'coerce'+-- @+--+-- When omitting the method definitions with GHC 7.4 and 7.6 a compile error will be triggered.+--+-- Consequently, if your code relies on these default methods make sure to state+--+-- > build-depends: newtype ^>= 0.2.2.0+--+-- In your @.cabal@ package description. class Newtype n o | n -> o where   pack :: o -> n+   unpack :: n -> o++#if  __GLASGOW_HASKELL__ >= 704+  default pack :: Coercible o n => o -> n+  pack = coerce++  default unpack :: Coercible n o => n -> o+  unpack = coerce+#endif++#if __GLASGOW_HASKELL__ >= 704 && !MIN_VERSION_base(4,7,0)+-- Hack: We define a dummy 'Coercible' class to force a+-- missing-instance compile error when methods are not explicitly+-- defined+class Coercible o n++coerce :: a -> b+coerce = undefined+#endif  {- TODO: for newtype-0.3 
Setup.hs view
@@ -1,2 +1,7 @@+ import Distribution.Simple++++ main = defaultMain
newtype.cabal view
@@ -1,7 +1,7 @@ cabal-version:       1.12 build-type:          Simple name:                newtype-version:             0.2.1.0+version:             0.2.2.0  license:             BSD3 license-file:        LICENSE@@ -22,7 +22,7 @@ library   exposed-modules:     Control.Newtype -  build-depends:       base >= 4.3 && < 4.14+  build-depends:       base >= 4.5 && < 4.14   if !impl(ghc >= 8.0)     build-depends:     transformers >= 0.2.2.0 && < 0.6