packages feed

instant-hashable (empty) → 0.1

raw patch · 6 files changed

+128/−0 lines, 6 filesdep +basedep +hashabledep +instant-genericssetup-changed

Dependencies added: base, hashable, instant-generics

Files

+ CHANGELOG.md view
@@ -0,0 +1,3 @@+# Version 0.1++* First 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,3 @@+`instant-hashable` allows you to generically derive `Data.Hashable.Hashable` instances+(from the `hashable` package) for your types using `instant-generics`,+which in particular, supports deriving generic representations for GADTs.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ instant-hashable.cabal view
@@ -0,0 +1,25 @@+name:                instant-hashable+version:             0.1+author:              Renzo Carbonara+maintainer:          renzo@carbonara.com.ar+copyright:           Renzo Carbonara 2015+license:             BSD3+license-file:        LICENSE.txt+category:            Web+build-type:          Simple+extra-source-files:  README.md CHANGELOG.md+cabal-version:       >=1.18+synopsis:            Generic Hashable instances through instant-generics++library+  hs-source-dirs: src/lib+  default-language: Haskell2010+  exposed-modules:+      Generics.Instant.Functions.Hashable+  build-depends:+      hashable >=1.2 && <1.3+    , base >=4.8 && <4.9+    , instant-generics >=0.4 && <0.5+  ghcjs-options: -Wall -O3+  ghc-options: -Wall -O2+
+ src/lib/Generics/Instant/Functions/Hashable.hs view
@@ -0,0 +1,65 @@+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE PolyKinds #-}++module Generics.Instant.Functions.Hashable+  ( -- $defaults+    ghashWithSalt+    -- * Internals+  , GHashable+  ) where++import           Data.Hashable (Hashable(hashWithSalt))+import           Generics.Instant++--------------------------------------------------------------------------------+-- $defaults+--+-- You can use 'ghashWithSalt' as your generic 'hashWithSalt' for any+-- 'Representable' type as follows:+--+-- @+-- instance 'Hashable' MyType where hashWithSalt = 'ghashWithSalt'+-- @++ghashWithSalt :: (Representable a, GHashable (Rep a)) => Int -> a -> Int+ghashWithSalt = \s a -> ghashWithSalt' s (from a)+{-# INLINABLE ghashWithSalt #-}++--------------------------------------------------------------------------------++class GHashable a where+  ghashWithSalt' :: Int -> a -> Int++instance GHashable Z where+  ghashWithSalt' _ _ = error+    "Generics.Instant.Functions.Hashable.GHashable Z ghashWithSalt' - impossible"++instance GHashable U where+  ghashWithSalt' s U = hashWithSalt s ()+  {-# INLINABLE ghashWithSalt' #-}++instance GHashable a => GHashable (CEq c p q a) where+  ghashWithSalt' s (C a) = ghashWithSalt' s a+  {-# INLINABLE ghashWithSalt' #-}++instance (GHashable a, GHashable b) => GHashable (a :*: b) where+  ghashWithSalt' s (a :*: b) = ghashWithSalt' (ghashWithSalt' s a) b+  {-# INLINABLE ghashWithSalt' #-}++instance (GHashable a, GHashable b) => GHashable (a :+: b) where+  ghashWithSalt' s lr = 0 `hashWithSalt` case lr of+    L a -> Left  (ghashWithSalt' s a)+    R b -> Right (ghashWithSalt' s b)+  {-# INLINABLE ghashWithSalt' #-}++instance Hashable a => GHashable (Var a) where+  ghashWithSalt' s (Var a) = hashWithSalt s a+  {-# INLINABLE ghashWithSalt' #-}++instance Hashable a => GHashable (Rec a) where+  ghashWithSalt' s (Rec a) = hashWithSalt s a+  {-# INLINABLE ghashWithSalt' #-}