Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use newtype deriving for newtypes #309

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
See also https://pvp.haskell.org/faq

## Version 1.4.6.0

* Use GND&DerivingVia to derive `newtype` intances (`Data.Semigroup`, `Data.Monoid`, `Identity` etc).

## Version 1.4.5.0

* Drop support for GHCs prior 8.6.5
Expand Down
2 changes: 1 addition & 1 deletion hashable.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.2
name: hashable
version: 1.4.5.0
version: 1.4.6.0
synopsis: A class for types that can be converted to a hash value
description:
This package defines a class, 'Hashable', for types that can be converted to a hash value.
Expand Down
90 changes: 32 additions & 58 deletions src/Data/Hashable/Class.hs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CApiFFI #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UnliftedFFITypes #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CApiFFI #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UnliftedFFITypes #-}

{-# OPTIONS_GHC -fno-warn-deprecations #-}

Expand Down Expand Up @@ -652,33 +656,19 @@ instance Hashable BSI.ShortByteString where

#if HAS_OS_STRING_filepath || HAS_OS_STRING_os_string
-- | @since 1.4.2.0
instance Hashable PosixString where
hash (PosixString s) = hash s
hashWithSalt salt (PosixString s) = hashWithSalt salt s
deriving newtype instance Hashable PosixString

-- | @since 1.4.2.0
instance Hashable WindowsString where
hash (WindowsString s) = hash s
hashWithSalt salt (WindowsString s) = hashWithSalt salt s
deriving newtype instance Hashable WindowsString

-- | @since 1.4.2.0
instance Hashable OsString where
hash (OsString s) = hash s
hashWithSalt salt (OsString s) = hashWithSalt salt s
deriving newtype instance Hashable OsString
#endif

#if HAS_OS_STRING_filepath && HAS_OS_STRING_os_string
instance Hashable FP.PosixString where
hash (FP.PosixString s) = hash s
hashWithSalt salt (FP.PosixString s) = hashWithSalt salt s

instance Hashable FP.WindowsString where
hash (FP.WindowsString s) = hash s
hashWithSalt salt (FP.WindowsString s) = hashWithSalt salt s

instance Hashable FP.OsString where
hash (FP.OsString s) = hash s
hashWithSalt salt (FP.OsString s) = hashWithSalt salt s
deriving newtype instance Hashable FP.PosixString
deriving newtype instance Hashable FP.WindowsString
deriving newtype instance Hashable FP.OsString
#endif

#if MIN_VERSION_text(2,0,0)
Expand Down Expand Up @@ -811,17 +801,14 @@ instance Hashable Version where
hashWithSalt salt (Version branch tags) =
salt `hashWithSalt` branch `hashWithSalt` tags

instance Hashable (Fixed a) where
hashWithSalt salt (MkFixed i) = hashWithSalt salt i
deriving newtype instance Hashable (Fixed a)

instance Hashable a => Hashable (Identity a) where
hashWithSalt = hashWithSalt1
deriving newtype instance Hashable a => Hashable (Identity a)
instance Hashable1 Identity where
liftHashWithSalt h salt (Identity x) = h salt x

-- Using hashWithSalt1 would cause needless constraint
instance Hashable a => Hashable (Const a b) where
hashWithSalt salt (Const x) = hashWithSalt salt x
deriving newtype instance Hashable a => Hashable (Const a b)

instance Hashable a => Hashable1 (Const a) where
liftHashWithSalt = defaultLiftHashWithSalt
Expand All @@ -843,34 +830,21 @@ instance Hashable a => Hashable (NE.NonEmpty a) where
instance Hashable1 NE.NonEmpty where
liftHashWithSalt h salt (a NE.:| as) = liftHashWithSalt h (h salt a) as

instance Hashable a => Hashable (Semi.Min a) where
hashWithSalt p (Semi.Min a) = hashWithSalt p a

instance Hashable a => Hashable (Semi.Max a) where
hashWithSalt p (Semi.Max a) = hashWithSalt p a
deriving newtype instance Hashable a => Hashable (Semi.Min a)
deriving newtype instance Hashable a => Hashable (Semi.Max a)

-- | __Note__: Prior to @hashable-1.3.0.0@ the hash computation included the second argument of 'Arg' which wasn't consistent with its 'Eq' instance.
--
-- @since 1.3.0.0
instance Hashable a => Hashable (Semi.Arg a b) where
hashWithSalt p (Semi.Arg a _) = hashWithSalt p a

instance Hashable a => Hashable (Semi.First a) where
hashWithSalt p (Semi.First a) = hashWithSalt p a


instance Hashable a => Hashable (Semi.Last a) where
hashWithSalt p (Semi.Last a) = hashWithSalt p a


instance Hashable a => Hashable (Semi.WrappedMonoid a) where
hashWithSalt p (Semi.WrapMonoid a) = hashWithSalt p a

deriving newtype instance Hashable a => Hashable (Semi.First a)
deriving newtype instance Hashable a => Hashable (Semi.Last a)
deriving newtype instance Hashable a => Hashable (Semi.WrappedMonoid a)

#if !MIN_VERSION_base(4,16,0)
instance Hashable a => Hashable (Semi.Option a) where
hashWithSalt p (Semi.Option a) = hashWithSalt p a

deriving newtype instance Hashable a => Hashable (Semi.Option a)
#endif

-- TODO: this instance is removed as there isn't Eq1 Min/Max, ...
Expand Down
Loading