-
Notifications
You must be signed in to change notification settings - Fork 85
Higher kinded classes #124
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
Merged
tibbe
merged 18 commits into
haskell-unordered-containers:master
from
andrewthad:higher_kinded_classes
Oct 29, 2016
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
cfee24f
add Hashable1 and Hashable2 with auxiliary functions
andrewthad 46dc659
Add instances and documentation
andrewthad f42e268
adapt generics support for Hashable1
andrewthad e190657
fix merge conflicts
andrewthad 9779db9
rename ToHash to HashArgs
andrewthad d84cfa5
add composition instance, remove Par1 GSum instance
andrewthad 833efbf
added more instances for Hashable1
andrewthad aae100e
add Hashable1 instance for Hashed. Add test that it abides by laws
andrewthad 0c09055
Add Hashable1 instances for Compose,Product,Sum
andrewthad ded8c87
improve warnings for old GHCs
andrewthad 7cd9bb4
add Eq1,Ord1,Show1 instances for Hashed, correct Show instance
andrewthad 088d725
remove unneeded constraint from Hashable Hashed instance
andrewthad acb9379
use showsUnaryWith instead of redefining it
andrewthad 39d5b29
add higher rank tuple instances, similar to grind in MMORPG
andrewthad fb9616b
Added examples for testing that hashes have not changed
andrewthad 77fd41a
make generic hashable of sums same as before
andrewthad a7f702b
add benchmarks for generics
andrewthad b6b9f6d
moved Hashed into Class module
andrewthad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,10 @@ import Data.Hashable.Class | |
import Data.Foldable (Foldable(foldr)) | ||
#endif | ||
|
||
#if MIN_VERSION_base(4,9,0) | ||
import Data.Functor.Classes (Eq1(..),Ord1(..),Show1(..)) | ||
#endif | ||
|
||
#ifdef GENERICS | ||
import Data.Hashable.Generic () | ||
#endif | ||
|
@@ -218,7 +222,7 @@ import Data.Hashable.Generic () | |
|
||
-- | A hashable value along with the result of the 'hash' function. | ||
data Hashed a = Hashed a {-# UNPACK #-} !Int | ||
deriving (Typeable,Show) | ||
deriving (Typeable) | ||
|
||
-- | Wrap a hashable value, caching the 'hash' function result. | ||
hashed :: Hashable a => a -> Hashed a | ||
|
@@ -235,6 +239,9 @@ instance Eq a => Eq (Hashed a) where | |
instance Ord a => Ord (Hashed a) where | ||
Hashed a _ `compare` Hashed b _ = a `compare` b | ||
|
||
instance Show a => Show (Hashed a) where | ||
showsPrec d (Hashed a _) = showsUnaryWith showsPrec "hashed" d a | ||
|
||
instance Hashable a => Hashable (Hashed a) where | ||
hashWithSalt = defaultHashWithSalt | ||
hash (Hashed _ h) = h | ||
|
@@ -251,3 +258,23 @@ instance (IsString a, Hashable a) => IsString (Hashed a) where | |
instance Foldable Hashed where | ||
foldr f acc (Hashed a _) = f a acc | ||
|
||
-- instances for @Data.Functor.Classes@ higher rank typeclasses | ||
-- in base-4.9 and onward. | ||
#if MIN_VERSION_base(4,9,0) | ||
instance Eq1 Hashed where | ||
liftEq f (Hashed a ha) (Hashed b hb) = ha == hb && f a b | ||
|
||
instance Ord1 Hashed where | ||
liftCompare f (Hashed a _) (Hashed b _) = f a b | ||
|
||
instance Show1 Hashed where | ||
liftShowsPrec sp _ d (Hashed a _) = showsUnaryWith sp "hashed" d a | ||
#endif | ||
|
||
-- This function is copied from Data.Functor.Classes, which does | ||
-- not export it. | ||
showsUnaryWith :: (Int -> a -> ShowS) -> String -> Int -> a -> ShowS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops. Thanks for pointing that out. |
||
showsUnaryWith sp name d x = showParen (d > 10) $ | ||
showString name . showChar ' ' . sp 11 x | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly for these instances. Shouldn't they be in
Lifted
? We might need to moveHashed
to an internal module to avoid the instances being orphaned.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think that putting it into Data.Hashable.Class would be alright? Or would you prefer a new internal module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class
is fine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has now been moved.