This file is indexed.

/usr/share/doc/libghc-hashable-doc/html/src/Data-Hashable-Lifted.html is in libghc-hashable-doc 1.2.6.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<!-- Generated by HsColour, http://code.haskell.org/~malcolm/hscolour/ -->
<title>Data/Hashable/Lifted.hs</title>
<link type='text/css' rel='stylesheet' href='hscolour.css' />
</head>
<body>
<pre><a name="line-1"></a><span class='hs-comment'>------------------------------------------------------------------------</span>
<a name="line-2"></a><span class='hs-comment'>-- |</span>
<a name="line-3"></a><span class='hs-comment'>-- Module      :  Data.Hashable.Class</span>
<a name="line-4"></a><span class='hs-comment'>-- Copyright   :  (c) Milan Straka 2010</span>
<a name="line-5"></a><span class='hs-comment'>--                (c) Johan Tibell 2011</span>
<a name="line-6"></a><span class='hs-comment'>--                (c) Bryan O'Sullivan 2011, 2012</span>
<a name="line-7"></a><span class='hs-comment'>-- License     :  BSD-style</span>
<a name="line-8"></a><span class='hs-comment'>-- Maintainer  :  johan.tibell@gmail.com</span>
<a name="line-9"></a><span class='hs-comment'>-- Stability   :  provisional</span>
<a name="line-10"></a><span class='hs-comment'>-- Portability :  portable</span>
<a name="line-11"></a><span class='hs-comment'>--</span>
<a name="line-12"></a><span class='hs-comment'>-- Lifting of the 'Hashable' class to unary and binary type constructors.</span>
<a name="line-13"></a><span class='hs-comment'>-- These classes are needed to express the constraints on arguments of</span>
<a name="line-14"></a><span class='hs-comment'>-- types that are parameterized by type constructors. Fixed-point data</span>
<a name="line-15"></a><span class='hs-comment'>-- types and monad transformers are such types.</span>
<a name="line-16"></a>
<a name="line-17"></a><span class='hs-keyword'>module</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Hashable</span><span class='hs-varop'>.</span><span class='hs-conid'>Lifted</span>
<a name="line-18"></a>    <span class='hs-layout'>(</span> <span class='hs-comment'>-- * Type Classes</span>
<a name="line-19"></a>      <span class='hs-conid'>Hashable1</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span>
<a name="line-20"></a>    <span class='hs-layout'>,</span> <span class='hs-conid'>Hashable2</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span>
<a name="line-21"></a>      <span class='hs-comment'>-- * Auxiliary Functions</span>
<a name="line-22"></a>    <span class='hs-layout'>,</span> <span class='hs-varid'>hashWithSalt1</span>
<a name="line-23"></a>    <span class='hs-layout'>,</span> <span class='hs-varid'>hashWithSalt2</span>
<a name="line-24"></a>    <span class='hs-layout'>,</span> <span class='hs-varid'>defaultLiftHashWithSalt</span>
<a name="line-25"></a>      <span class='hs-comment'>-- * Motivation</span>
<a name="line-26"></a>      <span class='hs-comment'>-- $motivation</span>
<a name="line-27"></a>    <span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-28"></a>
<a name="line-29"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Hashable</span><span class='hs-varop'>.</span><span class='hs-conid'>Class</span>
<a name="line-30"></a>
<a name="line-31"></a><span class='hs-comment'>-- $motivation</span>
<a name="line-32"></a><span class='hs-comment'>--</span>
<a name="line-33"></a><span class='hs-comment'>-- This type classes provided in this module are used to express constraints</span>
<a name="line-34"></a><span class='hs-comment'>-- on type constructors in a Haskell98-compatible fashion. As an example, consider</span>
<a name="line-35"></a><span class='hs-comment'>-- the following two types (Note that these instances are not actually provided</span>
<a name="line-36"></a><span class='hs-comment'>-- because @hashable@ does not have @transformers@ or @free@ as a dependency):</span>
<a name="line-37"></a><span class='hs-comment'>--</span>
<a name="line-38"></a><span class='hs-comment'>-- &gt; newtype WriterT w m a = WriterT { runWriterT :: m (a, w) }</span>
<a name="line-39"></a><span class='hs-comment'>-- &gt; data Free f a = Pure a | Free (f (Free f a))</span>
<a name="line-40"></a><span class='hs-comment'>--</span>
<a name="line-41"></a><span class='hs-comment'>-- The 'Hashable1' instances for @WriterT@ and @Free@ could be written as:</span>
<a name="line-42"></a><span class='hs-comment'>--</span>
<a name="line-43"></a><span class='hs-comment'>-- &gt; instance (Hashable w, Hashable1 m) =&gt; Hashable1 (WriterT w m) where</span>
<a name="line-44"></a><span class='hs-comment'>-- &gt;     liftHashWithSalt h s (WriterT m) =</span>
<a name="line-45"></a><span class='hs-comment'>-- &gt;         liftHashWithSalt (liftHashWithSalt2 h hashWithSalt) s m</span>
<a name="line-46"></a><span class='hs-comment'>-- &gt; instance Hashable1 f =&gt; Hashable1 (Free f) where</span>
<a name="line-47"></a><span class='hs-comment'>-- &gt;     liftHashWithSalt h = go where</span>
<a name="line-48"></a><span class='hs-comment'>-- &gt;         go s x = case x of</span>
<a name="line-49"></a><span class='hs-comment'>-- &gt;             Pure a -&gt; h s a</span>
<a name="line-50"></a><span class='hs-comment'>-- &gt;             Free p -&gt; liftHashWithSalt go s p</span>
<a name="line-51"></a><span class='hs-comment'>--</span>
<a name="line-52"></a><span class='hs-comment'>-- The 'Hashable' instances for these types can be trivially recovered with</span>
<a name="line-53"></a><span class='hs-comment'>-- 'hashWithSalt1':</span>
<a name="line-54"></a><span class='hs-comment'>--</span>
<a name="line-55"></a><span class='hs-comment'>-- &gt; instance (Hashable w, Hashable1 m, Hashable a) =&gt; Hashable (WriterT w m a) where</span>
<a name="line-56"></a><span class='hs-comment'>-- &gt;     hashWithSalt = hashWithSalt1</span>
<a name="line-57"></a><span class='hs-comment'>-- &gt; instance (Hashable1 f, Hashable a) =&gt; Hashable (Free f a) where</span>
<a name="line-58"></a><span class='hs-comment'>-- &gt;     hashWithSalt = hashWithSalt1</span>
<a name="line-59"></a>
<a name="line-60"></a><span class='hs-comment'>--</span>
<a name="line-61"></a><span class='hs-comment'>-- $discussion</span>
<a name="line-62"></a><span class='hs-comment'>--</span>
<a name="line-63"></a><span class='hs-comment'>-- Regardless of whether 'hashWithSalt1' is used to provide an implementation</span>
<a name="line-64"></a><span class='hs-comment'>-- of 'hashWithSalt', they should produce the same hash when called with</span>
<a name="line-65"></a><span class='hs-comment'>-- the same arguments. This is the only law that 'Hashable1' and 'Hashable2'</span>
<a name="line-66"></a><span class='hs-comment'>-- are expected to follow.</span>
<a name="line-67"></a><span class='hs-comment'>--</span>
<a name="line-68"></a><span class='hs-comment'>-- The typeclasses in this module only provide lifting for 'hashWithSalt', not</span>
<a name="line-69"></a><span class='hs-comment'>-- for 'hash'. This is because such liftings cannot be defined in a way that</span>
<a name="line-70"></a><span class='hs-comment'>-- would satisfy the @liftHash@ variant of the above law. As an illustration</span>
<a name="line-71"></a><span class='hs-comment'>-- of the problem we run into, let us assume that 'Hashable1' were</span>
<a name="line-72"></a><span class='hs-comment'>-- given a 'liftHash' method:</span>
<a name="line-73"></a><span class='hs-comment'>--</span>
<a name="line-74"></a><span class='hs-comment'>-- &gt; class Hashable1 t where</span>
<a name="line-75"></a><span class='hs-comment'>-- &gt;     liftHash :: (Int -&gt; a) -&gt; t a -&gt; Int</span>
<a name="line-76"></a><span class='hs-comment'>-- &gt;     liftHashWithSalt :: (Int -&gt; a -&gt; Int) -&gt; Int -&gt; t a -&gt; Int</span>
<a name="line-77"></a><span class='hs-comment'>--</span>
<a name="line-78"></a><span class='hs-comment'>-- Even for a type as simple as 'Maybe', the problem manifests itself. The</span>
<a name="line-79"></a><span class='hs-comment'>-- 'Hashable' instance for 'Maybe' is:</span>
<a name="line-80"></a><span class='hs-comment'>--</span>
<a name="line-81"></a><span class='hs-comment'>-- &gt; distinguisher :: Int</span>
<a name="line-82"></a><span class='hs-comment'>-- &gt; distinguisher = ...</span>
<a name="line-83"></a><span class='hs-comment'>-- &gt;</span>
<a name="line-84"></a><span class='hs-comment'>-- &gt; instance Hashable a =&gt; Hashable (Maybe a) where</span>
<a name="line-85"></a><span class='hs-comment'>-- &gt;     hash Nothing = 0</span>
<a name="line-86"></a><span class='hs-comment'>-- &gt;     hash (Just a) = distinguisher `hashWithSalt` a</span>
<a name="line-87"></a><span class='hs-comment'>-- &gt;     hashWithSalt s Nothing = ...</span>
<a name="line-88"></a><span class='hs-comment'>-- &gt;     hashWithSalt s (Just a) = ...</span>
<a name="line-89"></a><span class='hs-comment'>--</span>
<a name="line-90"></a><span class='hs-comment'>-- The implementation of 'hash' calls 'hashWithSalt' on @a@. The hypothetical</span>
<a name="line-91"></a><span class='hs-comment'>-- @liftHash@ defined earlier only accepts an argument that corresponds to</span>
<a name="line-92"></a><span class='hs-comment'>-- the implementation of 'hash' for @a@. Consequently, this formulation of</span>
<a name="line-93"></a><span class='hs-comment'>-- @liftHash@ would not provide a way to match the current behavior of 'hash'</span>
<a name="line-94"></a><span class='hs-comment'>-- for 'Maybe'. This problem gets worse when 'Either' and @[]@ are considered.</span>
<a name="line-95"></a><span class='hs-comment'>-- The solution adopted in this library is to omit @liftHash@ entirely.</span>
<a name="line-96"></a>
</pre></body>
</html>