exinst-hashable (empty) → 0.1
raw patch · 6 files changed
+163/−0 lines, 6 filesdep +basedep +constraintsdep +exinstsetup-changed
Dependencies added: base, constraints, exinst, hashable, singletons
Files
- CHANGELOG.md +3/−0
- LICENSE.txt +30/−0
- README.md +2/−0
- Setup.hs +2/−0
- exinst-hashable.cabal +28/−0
- src/lib/Exinst/Instances/Hashable.hs +98/−0
+ CHANGELOG.md view
@@ -0,0 +1,3 @@+# Version 0.1++* Initial release.
+ LICENSE.txt view
@@ -0,0 +1,30 @@+Copyright (c) 2015, Renzo Carbonara++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * 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.++ * Neither the name of Renzo Carbonara nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"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 COPYRIGHT+OWNER 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.
+ README.md view
@@ -0,0 +1,2 @@+See the README file in the @exinst@ package for more general documentation:+https://hackage.haskell.org/package/exinst#readme
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ exinst-hashable.cabal view
@@ -0,0 +1,28 @@+name: exinst-hashable+version: 0.1+author: Renzo Carbonara+maintainer: renzoλcarbonara.com.ar+copyright: Renzo Carbonara 2015+license: BSD3+license-file: LICENSE.txt+extra-source-files: README.md CHANGELOG.md+category: Data+build-type: Simple+cabal-version: >=1.18+synopsis: Derive instances for the `hashable` library for your existential types.+homepage: https://github.com/k0001/exinst+bug-reports: https://github.com/k0001/exinst/issues++library+ hs-source-dirs: src/lib+ default-language: Haskell2010+ exposed-modules:+ Exinst.Instances.Hashable+ build-depends:+ base >=4.7 && <4.9+ , hashable >=1.2 && <1.3+ , constraints >=0.4 && <0.5+ , exinst >=0.1 && <0.2+ , singletons >=1.1 && <1.2+ ghcjs-options: -Wall -O3+ ghc-options: -Wall -O2
+ src/lib/Exinst/Instances/Hashable.hs view
@@ -0,0 +1,98 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE UndecidableInstances #-}++{-# OPTIONS_GHC -fno-warn-orphans #-}++-- | This module exports 'Hashable' instances for 'Some1', 'Some2', 'Some3' and+-- 'Some4' from "Exinst.Singletons", provided situable 'Dict1', 'Dict2', 'Dict3'+-- and 'Dict4' instances are available.+--+-- See the README file in the @exinst@ package for more general documentation:+-- https://hackage.haskell.org/package/exinst#readme+module Exinst.Instances.Hashable () where++import Data.Hashable (Hashable(hashWithSalt))+import Data.Constraint+import Data.Singletons+import Exinst.Singletons+import Prelude++--------------------------------------------------------------------------------++-- | Some salt we add to hashes calculated in this module.+salt0 :: Int+salt0 = 6700417++--------------------------------------------------------------------------------++instance forall (f1 :: k1 -> *)+ . ( SingKind ('KProxy :: KProxy k1)+ , Hashable (DemoteRep ('KProxy :: KProxy k1))+ , Dict1 Hashable f1+ ) => Hashable (Some1 f1)+ where+ {-# INLINABLE hashWithSalt #-}+ hashWithSalt salt some1x = withSome1Sing some1x $ \sa1 (x :: f1 a1) ->+ case dict1 sa1 :: Dict (Hashable (f1 a1)) of+ Dict -> salt `hashWithSalt` salt0+ `hashWithSalt` fromSing sa1+ `hashWithSalt` x++instance forall (f2 :: k2 -> k1 -> *)+ . ( SingKind ('KProxy :: KProxy k2)+ , SingKind ('KProxy :: KProxy k1)+ , Hashable (DemoteRep ('KProxy :: KProxy k2))+ , Hashable (DemoteRep ('KProxy :: KProxy k1))+ , Dict2 Hashable f2+ ) => Hashable (Some2 f2)+ where+ {-# INLINABLE hashWithSalt #-}+ hashWithSalt salt some2x = withSome2Sing some2x $ \sa2 sa1 (x :: f2 a2 a1) ->+ case dict2 sa2 sa1 :: Dict (Hashable (f2 a2 a1)) of+ Dict -> salt `hashWithSalt` salt0+ `hashWithSalt` fromSing sa2+ `hashWithSalt` fromSing sa1+ `hashWithSalt` x++instance forall (f3 :: k3 -> k2 -> k1 -> *)+ . ( SingKind ('KProxy :: KProxy k3)+ , SingKind ('KProxy :: KProxy k2)+ , SingKind ('KProxy :: KProxy k1)+ , Hashable (DemoteRep ('KProxy :: KProxy k3))+ , Hashable (DemoteRep ('KProxy :: KProxy k2))+ , Hashable (DemoteRep ('KProxy :: KProxy k1))+ , Dict3 Hashable f3+ ) => Hashable (Some3 f3)+ where+ {-# INLINABLE hashWithSalt #-}+ hashWithSalt salt some3x = withSome3Sing some3x $ \sa3 sa2 sa1 (x :: f3 a3 a2 a1) ->+ case dict3 sa3 sa2 sa1 :: Dict (Hashable (f3 a3 a2 a1)) of+ Dict -> salt `hashWithSalt` salt0+ `hashWithSalt` fromSing sa3+ `hashWithSalt` fromSing sa2+ `hashWithSalt` fromSing sa1+ `hashWithSalt` x++instance forall (f4 :: k4 -> k3 -> k2 -> k1 -> *)+ . ( SingKind ('KProxy :: KProxy k4)+ , SingKind ('KProxy :: KProxy k3)+ , SingKind ('KProxy :: KProxy k2)+ , SingKind ('KProxy :: KProxy k1)+ , Hashable (DemoteRep ('KProxy :: KProxy k4))+ , Hashable (DemoteRep ('KProxy :: KProxy k3))+ , Hashable (DemoteRep ('KProxy :: KProxy k2))+ , Hashable (DemoteRep ('KProxy :: KProxy k1))+ , Dict4 Hashable f4+ ) => Hashable (Some4 f4)+ where+ {-# INLINABLE hashWithSalt #-}+ hashWithSalt salt some4x = withSome4Sing some4x $ \sa4 sa3 sa2 sa1 (x :: f4 a4 a3 a2 a1) ->+ case dict4 sa4 sa3 sa2 sa1 :: Dict (Hashable (f4 a4 a3 a2 a1)) of+ Dict -> salt `hashWithSalt` salt0+ `hashWithSalt` fromSing sa4+ `hashWithSalt` fromSing sa3+ `hashWithSalt` fromSing sa2+ `hashWithSalt` fromSing sa1+ `hashWithSalt` x