hashable-extras-0.2.2/0000755000000000000000000000000012554573673012775 5ustar0000000000000000hashable-extras-0.2.2/.ghci0000644000000000000000000000012512554573673013706 0ustar0000000000000000:set -isrc -idist/build/autogen -optP-include -optPdist/build/autogen/cabal_macros.h hashable-extras-0.2.2/.gitignore0000644000000000000000000000010412554573673014760 0ustar0000000000000000dist docs wiki TAGS tags wip .DS_Store .*.swp .*.swo *.o *.hi *~ *# hashable-extras-0.2.2/.travis.yml0000644000000000000000000000122312554573673015104 0ustar0000000000000000language: haskell before_install: # Uncomment whenever hackage is down. # - mkdir -p ~/.cabal && cp travis/config ~/.cabal/config && cabal update - cabal update # Try installing some of the build-deps with apt-get for speed. - travis/cabal-apt-install $mode install: - cabal configure $mode - cabal build script: - $script && hlint src --cpp-define HLINT notifications: irc: channels: - "irc.freenode.org#haskell-lens" skip_join: true template: - "\x0313hashable-extras\x03/\x0306%{branch}\x03 \x0314%{commit}\x03 %{build_url} %{message}" env: - mode="--enable-tests" script="cabal test --show-details=always" hashable-extras-0.2.2/.vim.custom0000644000000000000000000000137712554573673015112 0ustar0000000000000000" Add the following to your .vimrc to automatically load this on startup " if filereadable(".vim.custom") " so .vim.custom " endif function StripTrailingWhitespace() let myline=line(".") let mycolumn = col(".") silent %s/ *$// call cursor(myline, mycolumn) endfunction " enable syntax highlighting syntax on " search for the tags file anywhere between here and / set tags=TAGS;/ " highlight tabs and trailing spaces set listchars=tab:‗‗,trail:‗ set list " f2 runs hasktags map :exec ":!hasktags -x -c --ignore src" " strip trailing whitespace before saving " au BufWritePre *.hs,*.markdown silent! cal StripTrailingWhitespace() " rebuild hasktags after saving au BufWritePost *.hs silent! :exec ":!hasktags -x -c --ignore src" hashable-extras-0.2.2/AUTHORS.markdown0000644000000000000000000000102612554573673015665 0ustar0000000000000000The suggestion for adding `Hashable1` and `Hashable2` came from prolonged discussions on the topic with Dan Doel. However, any errors in the implementation are my fault. * [Dan Doel](mailto:dan.doel@gmail.com) [@dolio](https://github.com/dolio) You can watch contributors carry on the quest for bragging rights in the [contributors graph](https://github.com/analytics/compensated/graphs/contributors). Omission from this list is by no means an attempt to discount your contribution. Thank you for all of your help! -Edward Kmett hashable-extras-0.2.2/CHANGELOG.markdown0000644000000000000000000000054312554573673016032 0ustar00000000000000000.2.2 ----- * Removed spurious `generic-deriving` dependency * Compiles warning-free on GHC 7.10 0.2.1 ----- * Support `bifunctors` 5 0.2 --- * Converted to `bifunctors` 4 0.1.1 ----- * Marked this package `Trustworthy` 0.1.0.1 ------- * Bumped dependency bounds for `generic-deriving`. 0.1 --- * Split from [https://github.com/analytics/hash](hash) hashable-extras-0.2.2/hashable-extras.cabal0000644000000000000000000000331412554573673017035 0ustar0000000000000000name: hashable-extras category: Data, Hash version: 0.2.2 license: BSD3 cabal-version: >= 1.8 license-file: LICENSE author: Edward A. Kmett maintainer: Edward A. Kmett stability: provisional homepage: http://github.com/analytics/hashable-extras/ bug-reports: http://github.com/analytics/hashable-extras/issues copyright: Copyright (C) 2013 Edward A. Kmett build-type: Custom tested-with: GHC == 7.4.1, GHC == 7.6.1 synopsis: Higher-rank Hashable description: This package provides higher rank analogues to the Hashable data type. . The need for these sometimes arises in the presence of polymorphic recursion. extra-source-files: .travis.yml .ghci .gitignore .vim.custom HLint.hs travis/cabal-apt-install travis/config AUTHORS.markdown README.markdown CHANGELOG.markdown source-repository head type: git location: git://github.com/analytics/hashable-extras.git -- You can disable the doctests test suite with -f-test-doctests flag test-doctests default: True manual: True library build-depends: base >= 4.3 && < 5, bifunctors >= 4 && < 6, bytestring >= 0.9 && < 0.11, hashable >= 1.1.2.3 && < 1.3, transformers >= 0.2 && < 0.5 exposed-modules: Data.Hashable.Extras ghc-options: -Wall -fwarn-tabs -O2 hs-source-dirs: src test-suite doctests type: exitcode-stdio-1.0 main-is: doctests.hs ghc-options: -Wall -threaded hs-source-dirs: tests if !flag(test-doctests) buildable: False else build-depends: base, directory >= 1.0, doctest >= 0.9.1, filepath hashable-extras-0.2.2/HLint.hs0000644000000000000000000000003412554573673014344 0ustar0000000000000000import "hint" HLint.Default hashable-extras-0.2.2/LICENSE0000644000000000000000000000236412554573673014007 0ustar0000000000000000Copyright 2012-2013 Edward Kmett All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. hashable-extras-0.2.2/README.markdown0000644000000000000000000000064112554573673015477 0ustar0000000000000000hashable-extras =============== [![Build Status](https://secure.travis-ci.org/ekmett/hashable-extras.png?branch=master)](http://travis-ci.org/ekmett/hashable-extras) This package provides higher order Hashable types Contact Information ------------------- Contributions and bug reports are welcome! Please feel free to contact me through github or on the #haskell IRC channel on irc.freenode.net. -Edward Kmett hashable-extras-0.2.2/Setup.lhs0000644000000000000000000000464412554573673014615 0ustar0000000000000000#!/usr/bin/runhaskell \begin{code} {-# OPTIONS_GHC -Wall #-} module Main (main) where import Data.List ( nub ) import Data.Version ( showVersion ) import Distribution.Package ( PackageName(PackageName), Package, PackageId, InstalledPackageId, packageVersion, packageName ) import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) ) import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks ) import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose, copyFiles ) import Distribution.Simple.BuildPaths ( autogenModulesDir ) import Distribution.Simple.Setup ( BuildFlags(buildVerbosity), Flag(..), fromFlag, HaddockFlags(haddockDistPref)) import Distribution.Simple.LocalBuildInfo ( withLibLBI, withTestLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps) ) import Distribution.Text ( display ) import Distribution.Verbosity ( Verbosity, normal ) import System.FilePath ( () ) main :: IO () main = defaultMainWithHooks simpleUserHooks { buildHook = \pkg lbi hooks flags -> do generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi buildHook simpleUserHooks pkg lbi hooks flags , postHaddock = \args flags pkg lbi -> do copyFiles normal (haddockOutputDir flags pkg) [] postHaddock simpleUserHooks args flags pkg lbi } haddockOutputDir :: Package p => HaddockFlags -> p -> FilePath haddockOutputDir flags pkg = destDir where baseDir = case haddockDistPref flags of NoFlag -> "." Flag x -> x destDir = baseDir "doc" "html" display (packageName pkg) generateBuildModule :: Verbosity -> PackageDescription -> LocalBuildInfo -> IO () generateBuildModule verbosity pkg lbi = do let dir = autogenModulesDir lbi createDirectoryIfMissingVerbose verbosity True dir withLibLBI pkg lbi $ \_ libcfg -> do withTestLBI pkg lbi $ \suite suitecfg -> do rewriteFile (dir "Build_" ++ testName suite ++ ".hs") $ unlines [ "module Build_" ++ testName suite ++ " where" , "deps :: [String]" , "deps = " ++ (show $ formatdeps (testDeps libcfg suitecfg)) ] where formatdeps = map (formatone . snd) formatone p = case packageName p of PackageName n -> n ++ "-" ++ showVersion (packageVersion p) testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)] testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys \end{code} hashable-extras-0.2.2/src/0000755000000000000000000000000012554573673013564 5ustar0000000000000000hashable-extras-0.2.2/src/Data/0000755000000000000000000000000012554573673014435 5ustar0000000000000000hashable-extras-0.2.2/src/Data/Hashable/0000755000000000000000000000000012554573673016144 5ustar0000000000000000hashable-extras-0.2.2/src/Data/Hashable/Extras.hs0000644000000000000000000000620212554573673017746 0ustar0000000000000000{-# LANGUAGE CPP #-} {-# LANGUAGE DefaultSignatures #-} #if __GLASGOW_HASKELL__ >= 702 && __GLASGOW_HASKELL__ < 710 {-# LANGUAGE Trustworthy #-} #endif -------------------------------------------------------------------- -- | -- Copyright : (c) Edward Kmett 2013 -- License : BSD3 -- Maintainer: Edward Kmett -- Stability : experimental -- Portability: non-portable -- -------------------------------------------------------------------- module Data.Hashable.Extras ( Hashable1(..) , Hashable2(..) , Hashed(..) , hashWith1 , hashWith2 , salt ) where import Data.Bifunctor import Data.Functor.Identity import Data.Hashable data Hashed = Hashed { unhashed :: Int -> Int } instance Hashable Hashed where hashWithSalt n f = unhashed f n {-# INLINE hashWithSalt #-} data Salt = Salt instance Hashable Salt where hashWithSalt = const {-# INLINE hashWithSalt #-} -- | Extract the default salt used by `Data.Hashable` salt :: Int salt = hash Salt class Hashable1 t where hashWithSalt1 :: Hashable a => Int -> t a -> Int #ifndef HLINT default hashWithSalt1 :: (Hashable a, Hashable (t a)) => Int -> t a -> Int hashWithSalt1 = hashWithSalt {-# INLINE hashWithSalt1 #-} #endif hash1 :: Hashable a => t a -> Int hash1 = hashWithSalt1 salt {-# INLINE hash1 #-} instance Hashable1 Identity where hashWithSalt1 n (Identity a) = hashWithSalt n a {-# INLINE hashWithSalt1 #-} instance Hashable1 Maybe instance Hashable1 [] instance Hashable a => Hashable1 (Either a) instance Hashable a => Hashable1 ((,) a) instance (Hashable a, Hashable b) => Hashable1 ((,,) a b) instance (Hashable a, Hashable b, Hashable c) => Hashable1 ((,,,) a b c) instance (Hashable a, Hashable b, Hashable c, Hashable d) => Hashable1 ((,,,,) a b c d) instance (Hashable a, Hashable b, Hashable c, Hashable d, Hashable e) => Hashable1 ((,,,,,) a b c d e) instance (Hashable a, Hashable b, Hashable c, Hashable d, Hashable e, Hashable f) => Hashable1 ((,,,,,,) a b c d e f) class Hashable2 t where hashWithSalt2 :: (Hashable a, Hashable b) => Int -> t a b -> Int #ifndef HLINT default hashWithSalt2 :: (Hashable a, Hashable b, Hashable (t a b)) => Int -> t a b -> Int hashWithSalt2 = hashWithSalt {-# INLINE hashWithSalt2 #-} #endif hash2 :: (Hashable a, Hashable b) => t a b -> Int hash2 = hashWithSalt2 salt {-# INLINE hash2 #-} instance Hashable2 Either instance Hashable2 (,) instance Hashable a => Hashable2 ((,,) a) instance (Hashable a, Hashable b) => Hashable2 ((,,,) a b) instance (Hashable a, Hashable b, Hashable c) => Hashable2 ((,,,,) a b c) instance (Hashable a, Hashable b, Hashable c, Hashable d) => Hashable2 ((,,,,,) a b c d) instance (Hashable a, Hashable b, Hashable c, Hashable d, Hashable e) => Hashable2 ((,,,,,,) a b c d e) hashWith1 :: (Functor t, Hashable1 t) => (Int -> a -> Int) -> Int -> t a -> Int hashWith1 h s ta = s `hashWithSalt1` fmap (\a -> Hashed (`h` a)) ta {-# INLINE hashWith1 #-} hashWith2 :: (Bifunctor t, Hashable2 t) => (Int -> a -> Int) -> (Int -> b -> Int) -> Int -> t a b -> Int hashWith2 h1 h2 s tab = s `hashWithSalt2` bimap (\a -> Hashed (`h1` a)) (\b -> Hashed (`h2` b)) tab {-# INLINE hashWith2 #-} hashable-extras-0.2.2/tests/0000755000000000000000000000000012554573673014137 5ustar0000000000000000hashable-extras-0.2.2/tests/doctests.hsc0000644000000000000000000000456712554573673016502 0ustar0000000000000000{-# LANGUAGE CPP #-} {-# LANGUAGE ForeignFunctionInterface #-} ----------------------------------------------------------------------------- -- | -- Module : Main (doctests) -- Copyright : (C) 2012-13 Edward Kmett -- License : BSD-style (see the file LICENSE) -- Maintainer : Edward Kmett -- Stability : provisional -- Portability : portable -- -- This module provides doctests for a project based on the actual versions -- of the packages it was built with. It requires a corresponding Setup.lhs -- to be added to the project ----------------------------------------------------------------------------- module Main where import Build_doctests (deps) #if __GLASGOW_HASKELL__ < 710 import Control.Applicative #endif import Control.Monad import Data.List import System.Directory import System.FilePath import Test.DocTest ##if defined(mingw32_HOST_OS) ##if defined(i386_HOST_ARCH) ##define USE_CP import Control.Applicative import Control.Exception import Foreign.C.Types foreign import stdcall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool foreign import stdcall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt ##elif defined(x86_64_HOST_ARCH) ##define USE_CP import Control.Applicative import Control.Exception import Foreign.C.Types foreign import ccall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool foreign import ccall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt ##endif ##endif -- | Run in a modified codepage where we can print UTF-8 values on Windows. withUnicode :: IO a -> IO a ##ifdef USE_CP withUnicode m = do cp <- c_GetConsoleCP (c_SetConsoleCP 65001 >> m) `finally` c_SetConsoleCP cp ##else withUnicode m = m ##endif main :: IO () main = withUnicode $ getSources >>= \sources -> doctest $ "-isrc" : "-idist/build/autogen" : "-optP-include" : "-optPdist/build/autogen/cabal_macros.h" : "-hide-all-packages" : "-Iincludes" : map ("-package="++) deps ++ sources getSources :: IO [FilePath] getSources = filter (isSuffixOf ".hs") <$> go "src" where go dir = do (dirs, files) <- getFilesAndDirectories dir (files ++) . concat <$> mapM go dirs getFilesAndDirectories :: FilePath -> IO ([FilePath], [FilePath]) getFilesAndDirectories dir = do c <- map (dir ) . filter (`notElem` ["..", "."]) <$> getDirectoryContents dir (,) <$> filterM doesDirectoryExist c <*> filterM doesFileExist c hashable-extras-0.2.2/travis/0000755000000000000000000000000012554573673014305 5ustar0000000000000000hashable-extras-0.2.2/travis/cabal-apt-install0000755000000000000000000000127212554573673017525 0ustar0000000000000000#! /bin/bash set -eu APT="sudo apt-get -q -y" CABAL_INSTALL_DEPS="cabal install --only-dependencies --force-reinstall" $APT update $APT install dctrl-tools # Find potential system packages to satisfy cabal dependencies deps() { local M='^\([^ ]\+\)-[0-9.]\+ (.*$' local G=' -o ( -FPackage -X libghc-\L\1\E-dev )' local E="$($CABAL_INSTALL_DEPS "$@" --dry-run -v 2> /dev/null \ | sed -ne "s/$M/$G/p" | sort -u)" grep-aptavail -n -sPackage \( -FNone -X None \) $E | sort -u } $APT install $(deps "$@") libghc-quickcheck2-dev # QuickCheck is special $CABAL_INSTALL_DEPS "$@" # Install the rest via Hackage if ! $APT install hlint ; then $APT install $(deps hlint) cabal install hlint fi hashable-extras-0.2.2/travis/config0000644000000000000000000000120612554573673015474 0ustar0000000000000000-- This provides a custom ~/.cabal/config file for use when hackage is down that should work on unix -- -- This is particularly useful for travis-ci to get it to stop complaining -- about a broken build when everything is still correct on our end. -- -- This uses Luite Stegeman's mirror of hackage provided by his 'hdiff' site instead -- -- To enable this, uncomment the before_script in .travis.yml remote-repo: hdiff.luite.com:http://hdiff.luite.com/packages/archive remote-repo-cache: ~/.cabal/packages world-file: ~/.cabal/world build-summary: ~/.cabal/logs/build.log remote-build-reporting: anonymous install-dirs user install-dirs global