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.0In your .cabal package description.
Instances20Newtype, …
Newtype All BoolDefined in newtype-0.2.2.0 · Control.NewtypeNewtype Any BoolDefined in newtype-0.2.2.0 · Control.NewtypeNewtype (Identity a) aDefined in newtype-0.2.2.0 · Control.NewtypeNewtype (Down a) aDefined in newtype-0.2.2.0 · Control.NewtypeNOTE: Type & instance only available with
base ≥ 4.6.0Newtype (Dual a) aDefined in newtype-0.2.2.0 · Control.NewtypeNewtype (Product a) aDefined in newtype-0.2.2.0 · Control.NewtypeNewtype (Sum a) aDefined in newtype-0.2.2.0 · Control.NewtypeNewtype (First a) (Maybe a)Defined in newtype-0.2.2.0 · Control.NewtypeNewtype (Last a) (Maybe a)Defined in newtype-0.2.2.0 · Control.NewtypeNewtype (ZipList a) [a]Defined in newtype-0.2.2.0 · Control.NewtypeNewtype (Endo a) (a -> a)Defined in newtype-0.2.2.0 · Control.NewtypeNewtype (Fixed a) IntegerDefined in newtype-0.2.2.0 · Control.NewtypeNewtype (WrappedMonad m a) (m a)Defined in newtype-0.2.2.0 · Control.NewtypeArrowApply a => Newtype (ArrowMonad a b) (a () b)Defined in newtype-0.2.2.0 · Control.NewtypeNewtype (Const a x) aDefined in newtype-0.2.2.0 · Control.NewtypeNewtype (Ap f a) (f a)Defined in newtype-0.2.2.0 · Control.NewtypeNOTE: Type & instance only available with
base ≥ 4.12.0Newtype (Alt f a) (f a)Defined in newtype-0.2.2.0 · Control.NewtypeNOTE: Type & instance only available with
base ≥ 4.8.0Newtype (WrappedArrow a b c) (a b c)Defined in newtype-0.2.2.0 · Control.NewtypeNewtype (Kleisli m a b) (a -> m b)Defined in newtype-0.2.2.0 · Control.NewtypeNewtype (Compose f g a) (f (g a))Defined in newtype-0.2.2.0 · Control.Newtype