/usr/share/doc/libghc-syb-doc/html/src/Data-Generics-Twins.html is in libghc-syb-doc 0.6-3.
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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | <?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>src/Data/Generics/Twins.hs</title>
<link type='text/css' rel='stylesheet' href='hscolour.css' />
</head>
<body>
<pre><a name="line-1"></a><span class='hs-comment'>{-# LANGUAGE RankNTypes, ScopedTypeVariables, CPP #-}</span>
<a name="line-2"></a><span class='hs-comment'>-----------------------------------------------------------------------------</span>
<a name="line-3"></a><span class='hs-comment'>-- |</span>
<a name="line-4"></a><span class='hs-comment'>-- Module : Data.Generics.Twins</span>
<a name="line-5"></a><span class='hs-comment'>-- Copyright : (c) The University of Glasgow, CWI 2001--2004</span>
<a name="line-6"></a><span class='hs-comment'>-- License : BSD-style (see the LICENSE file)</span>
<a name="line-7"></a><span class='hs-comment'>--</span>
<a name="line-8"></a><span class='hs-comment'>-- Maintainer : generics@haskell.org</span>
<a name="line-9"></a><span class='hs-comment'>-- Stability : experimental</span>
<a name="line-10"></a><span class='hs-comment'>-- Portability : non-portable (local universal quantification)</span>
<a name="line-11"></a><span class='hs-comment'>--</span>
<a name="line-12"></a><span class='hs-comment'>-- \"Scrap your boilerplate\" --- Generic programming in Haskell</span>
<a name="line-13"></a><span class='hs-comment'>-- See <<a href="http://www.cs.uu.nl/wiki/GenericProgramming/SYB">http://www.cs.uu.nl/wiki/GenericProgramming/SYB</a>>. The present module</span>
<a name="line-14"></a><span class='hs-comment'>-- provides support for multi-parameter traversal, which is also</span>
<a name="line-15"></a><span class='hs-comment'>-- demonstrated with generic operations like equality.</span>
<a name="line-16"></a><span class='hs-comment'>--</span>
<a name="line-17"></a><span class='hs-comment'>-----------------------------------------------------------------------------</span>
<a name="line-18"></a>
<a name="line-19"></a><span class='hs-keyword'>module</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Generics</span><span class='hs-varop'>.</span><span class='hs-conid'>Twins</span> <span class='hs-layout'>(</span>
<a name="line-20"></a>
<a name="line-21"></a> <span class='hs-comment'>-- * Generic folds and maps that also accumulate</span>
<a name="line-22"></a> <span class='hs-varid'>gfoldlAccum</span><span class='hs-layout'>,</span>
<a name="line-23"></a> <span class='hs-varid'>gmapAccumT</span><span class='hs-layout'>,</span>
<a name="line-24"></a> <span class='hs-varid'>gmapAccumM</span><span class='hs-layout'>,</span>
<a name="line-25"></a> <span class='hs-varid'>gmapAccumQl</span><span class='hs-layout'>,</span>
<a name="line-26"></a> <span class='hs-varid'>gmapAccumQr</span><span class='hs-layout'>,</span>
<a name="line-27"></a> <span class='hs-varid'>gmapAccumQ</span><span class='hs-layout'>,</span>
<a name="line-28"></a> <span class='hs-varid'>gmapAccumA</span><span class='hs-layout'>,</span>
<a name="line-29"></a>
<a name="line-30"></a> <span class='hs-comment'>-- * Mapping combinators for twin traversal</span>
<a name="line-31"></a> <span class='hs-varid'>gzipWithT</span><span class='hs-layout'>,</span>
<a name="line-32"></a> <span class='hs-varid'>gzipWithM</span><span class='hs-layout'>,</span>
<a name="line-33"></a> <span class='hs-varid'>gzipWithQ</span><span class='hs-layout'>,</span>
<a name="line-34"></a>
<a name="line-35"></a> <span class='hs-comment'>-- * Typical twin traversals</span>
<a name="line-36"></a> <span class='hs-varid'>geq</span><span class='hs-layout'>,</span>
<a name="line-37"></a> <span class='hs-varid'>gzip</span><span class='hs-layout'>,</span>
<a name="line-38"></a> <span class='hs-varid'>gcompare</span>
<a name="line-39"></a>
<a name="line-40"></a> <span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-41"></a>
<a name="line-42"></a>
<a name="line-43"></a><span class='hs-comment'>------------------------------------------------------------------------------</span>
<a name="line-44"></a>
<a name="line-45"></a><span class='hs-cpp'>#ifdef __HADDOCK__</span>
<a name="line-46"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Prelude</span>
<a name="line-47"></a><span class='hs-cpp'>#endif</span>
<a name="line-48"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Data</span>
<a name="line-49"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Generics</span><span class='hs-varop'>.</span><span class='hs-conid'>Aliases</span>
<a name="line-50"></a>
<a name="line-51"></a><span class='hs-cpp'>#ifdef __GLASGOW_HASKELL__</span>
<a name="line-52"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Prelude</span> <span class='hs-varid'>hiding</span> <span class='hs-layout'>(</span> <span class='hs-conid'>GT</span> <span class='hs-layout'>)</span>
<a name="line-53"></a><span class='hs-cpp'>#endif</span>
<a name="line-54"></a>
<a name="line-55"></a><span class='hs-cpp'>#if __GLASGOW_HASKELL__ < 709</span>
<a name="line-56"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Applicative</span> <span class='hs-layout'>(</span><span class='hs-conid'>Applicative</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-57"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Monoid</span> <span class='hs-layout'>(</span> <span class='hs-varid'>mappend</span><span class='hs-layout'>,</span> <span class='hs-varid'>mconcat</span> <span class='hs-layout'>)</span>
<a name="line-58"></a><span class='hs-cpp'>#endif</span>
<a name="line-59"></a>
<a name="line-60"></a><span class='hs-comment'>------------------------------------------------------------------------------</span>
<a name="line-61"></a>
<a name="line-62"></a>
<a name="line-63"></a><span class='hs-comment'>------------------------------------------------------------------------------</span>
<a name="line-64"></a><span class='hs-comment'>--</span>
<a name="line-65"></a><span class='hs-comment'>-- Generic folds and maps that also accumulate</span>
<a name="line-66"></a><span class='hs-comment'>--</span>
<a name="line-67"></a><span class='hs-comment'>------------------------------------------------------------------------------</span>
<a name="line-68"></a>
<a name="line-69"></a><span class='hs-comment'>{--------------------------------------------------------------
<a name="line-70"></a>
<a name="line-71"></a>A list map can be elaborated to perform accumulation.
<a name="line-72"></a>In the same sense, we can elaborate generic maps over terms.
<a name="line-73"></a>
<a name="line-74"></a>We recall the type of map:
<a name="line-75"></a>map :: (a -> b) -> [a] -> [b]
<a name="line-76"></a>
<a name="line-77"></a>We recall the type of an accumulating map (see Data.List):
<a name="line-78"></a>mapAccumL :: (a -> b -> (a,c)) -> a -> [b] -> (a,[c])
<a name="line-79"></a>
<a name="line-80"></a>Applying the same scheme we obtain an accumulating gfoldl.
<a name="line-81"></a>
<a name="line-82"></a>--------------------------------------------------------------}</span>
<a name="line-83"></a>
<a name="line-84"></a><span class='hs-comment'>-- | gfoldl with accumulation</span>
<a name="line-85"></a>
<a name="line-86"></a><a name="gfoldlAccum"></a><span class='hs-definition'>gfoldlAccum</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Data</span> <span class='hs-varid'>d</span>
<a name="line-87"></a> <span class='hs-keyglyph'>=></span> <span class='hs-layout'>(</span><span class='hs-keyword'>forall</span> <span class='hs-varid'>e</span> <span class='hs-varid'>r</span><span class='hs-varop'>.</span> <span class='hs-conid'>Data</span> <span class='hs-varid'>e</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>c</span> <span class='hs-layout'>(</span><span class='hs-varid'>e</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>r</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>e</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>c</span> <span class='hs-varid'>r</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-88"></a> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-keyword'>forall</span> <span class='hs-varid'>g</span><span class='hs-varop'>.</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>c</span> <span class='hs-varid'>g</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-89"></a> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>c</span> <span class='hs-varid'>d</span><span class='hs-layout'>)</span>
<a name="line-90"></a>
<a name="line-91"></a><span class='hs-definition'>gfoldlAccum</span> <span class='hs-varid'>k</span> <span class='hs-varid'>z</span> <span class='hs-varid'>a0</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>unA</span> <span class='hs-layout'>(</span><span class='hs-varid'>gfoldl</span> <span class='hs-varid'>k'</span> <span class='hs-varid'>z'</span> <span class='hs-varid'>d</span><span class='hs-layout'>)</span> <span class='hs-varid'>a0</span>
<a name="line-92"></a> <span class='hs-keyword'>where</span>
<a name="line-93"></a> <span class='hs-varid'>k'</span> <span class='hs-varid'>c</span> <span class='hs-varid'>y</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>A</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-varid'>a'</span><span class='hs-layout'>,</span> <span class='hs-varid'>c'</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>unA</span> <span class='hs-varid'>c</span> <span class='hs-varid'>a</span> <span class='hs-keyword'>in</span> <span class='hs-varid'>k</span> <span class='hs-varid'>a'</span> <span class='hs-varid'>c'</span> <span class='hs-varid'>y</span><span class='hs-layout'>)</span>
<a name="line-94"></a> <span class='hs-varid'>z'</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>A</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>z</span> <span class='hs-varid'>a</span> <span class='hs-varid'>f</span><span class='hs-layout'>)</span>
<a name="line-95"></a>
<a name="line-96"></a>
<a name="line-97"></a><a name="A"></a><span class='hs-comment'>-- | A type constructor for accumulation</span>
<a name="line-98"></a><a name="A"></a><span class='hs-keyword'>newtype</span> <span class='hs-conid'>A</span> <span class='hs-varid'>a</span> <span class='hs-varid'>c</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>A</span> <span class='hs-layout'>{</span> <span class='hs-varid'>unA</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>c</span> <span class='hs-varid'>d</span><span class='hs-layout'>)</span> <span class='hs-layout'>}</span>
<a name="line-99"></a>
<a name="line-100"></a>
<a name="line-101"></a><a name="gmapAccumT"></a><span class='hs-comment'>-- | gmapT with accumulation</span>
<a name="line-102"></a><span class='hs-definition'>gmapAccumT</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Data</span> <span class='hs-varid'>d</span>
<a name="line-103"></a> <span class='hs-keyglyph'>=></span> <span class='hs-layout'>(</span><span class='hs-keyword'>forall</span> <span class='hs-varid'>e</span><span class='hs-varop'>.</span> <span class='hs-conid'>Data</span> <span class='hs-varid'>e</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>e</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>e</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-104"></a> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>d</span><span class='hs-layout'>)</span>
<a name="line-105"></a><span class='hs-definition'>gmapAccumT</span> <span class='hs-varid'>f</span> <span class='hs-varid'>a0</span> <span class='hs-varid'>d0</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-varid'>a1</span><span class='hs-layout'>,</span> <span class='hs-varid'>d1</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>gfoldlAccum</span> <span class='hs-varid'>k</span> <span class='hs-varid'>z</span> <span class='hs-varid'>a0</span> <span class='hs-varid'>d0</span>
<a name="line-106"></a> <span class='hs-keyword'>in</span> <span class='hs-layout'>(</span><span class='hs-varid'>a1</span><span class='hs-layout'>,</span> <span class='hs-varid'>unID</span> <span class='hs-varid'>d1</span><span class='hs-layout'>)</span>
<a name="line-107"></a> <span class='hs-keyword'>where</span>
<a name="line-108"></a> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span> <span class='hs-layout'>(</span><span class='hs-conid'>ID</span> <span class='hs-varid'>c</span><span class='hs-layout'>)</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-varid'>a'</span><span class='hs-layout'>,</span><span class='hs-varid'>d'</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>f</span> <span class='hs-varid'>a</span> <span class='hs-varid'>d</span>
<a name="line-109"></a> <span class='hs-keyword'>in</span> <span class='hs-layout'>(</span><span class='hs-varid'>a'</span><span class='hs-layout'>,</span> <span class='hs-conid'>ID</span> <span class='hs-layout'>(</span><span class='hs-varid'>c</span> <span class='hs-varid'>d'</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-110"></a> <span class='hs-varid'>z</span> <span class='hs-varid'>a</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>ID</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span>
<a name="line-111"></a>
<a name="line-112"></a>
<a name="line-113"></a><a name="gmapAccumA"></a><span class='hs-comment'>-- | Applicative version</span>
<a name="line-114"></a><span class='hs-definition'>gmapAccumA</span> <span class='hs-keyglyph'>::</span> <span class='hs-keyword'>forall</span> <span class='hs-varid'>b</span> <span class='hs-varid'>d</span> <span class='hs-varid'>a</span><span class='hs-varop'>.</span> <span class='hs-layout'>(</span><span class='hs-conid'>Data</span> <span class='hs-varid'>d</span><span class='hs-layout'>,</span> <span class='hs-conid'>Applicative</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span>
<a name="line-115"></a> <span class='hs-keyglyph'>=></span> <span class='hs-layout'>(</span><span class='hs-keyword'>forall</span> <span class='hs-varid'>e</span><span class='hs-varop'>.</span> <span class='hs-conid'>Data</span> <span class='hs-varid'>e</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>e</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>b</span><span class='hs-layout'>,</span> <span class='hs-varid'>a</span> <span class='hs-varid'>e</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-116"></a> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>b</span><span class='hs-layout'>,</span> <span class='hs-varid'>a</span> <span class='hs-varid'>d</span><span class='hs-layout'>)</span>
<a name="line-117"></a><span class='hs-definition'>gmapAccumA</span> <span class='hs-varid'>f</span> <span class='hs-varid'>a0</span> <span class='hs-varid'>d0</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>gfoldlAccum</span> <span class='hs-varid'>k</span> <span class='hs-varid'>z</span> <span class='hs-varid'>a0</span> <span class='hs-varid'>d0</span>
<a name="line-118"></a> <span class='hs-keyword'>where</span>
<a name="line-119"></a> <span class='hs-varid'>k</span> <span class='hs-keyglyph'>::</span> <span class='hs-keyword'>forall</span> <span class='hs-varid'>d'</span> <span class='hs-varid'>e</span><span class='hs-varop'>.</span> <span class='hs-layout'>(</span><span class='hs-conid'>Data</span> <span class='hs-varid'>d'</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span>
<a name="line-120"></a> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-layout'>(</span><span class='hs-varid'>d'</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>e</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>d'</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>b</span><span class='hs-layout'>,</span> <span class='hs-varid'>a</span> <span class='hs-varid'>e</span><span class='hs-layout'>)</span>
<a name="line-121"></a> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span> <span class='hs-varid'>c</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-varid'>a'</span><span class='hs-layout'>,</span><span class='hs-varid'>d'</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>f</span> <span class='hs-varid'>a</span> <span class='hs-varid'>d</span>
<a name="line-122"></a> <span class='hs-varid'>c'</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>c</span> <span class='hs-varop'><*></span> <span class='hs-varid'>d'</span>
<a name="line-123"></a> <span class='hs-keyword'>in</span> <span class='hs-layout'>(</span><span class='hs-varid'>a'</span><span class='hs-layout'>,</span> <span class='hs-varid'>c'</span><span class='hs-layout'>)</span>
<a name="line-124"></a> <span class='hs-varid'>z</span> <span class='hs-keyglyph'>::</span> <span class='hs-keyword'>forall</span> <span class='hs-varid'>t</span> <span class='hs-varid'>c</span> <span class='hs-varid'>a'</span><span class='hs-varop'>.</span> <span class='hs-layout'>(</span><span class='hs-conid'>Applicative</span> <span class='hs-varid'>a'</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span>
<a name="line-125"></a> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>c</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>t</span><span class='hs-layout'>,</span> <span class='hs-varid'>a'</span> <span class='hs-varid'>c</span><span class='hs-layout'>)</span>
<a name="line-126"></a> <span class='hs-varid'>z</span> <span class='hs-varid'>a</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>pure</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span>
<a name="line-127"></a>
<a name="line-128"></a>
<a name="line-129"></a><a name="gmapAccumM"></a><span class='hs-comment'>-- | gmapM with accumulation</span>
<a name="line-130"></a><span class='hs-definition'>gmapAccumM</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-conid'>Data</span> <span class='hs-varid'>d</span><span class='hs-layout'>,</span> <span class='hs-conid'>Monad</span> <span class='hs-varid'>m</span><span class='hs-layout'>)</span>
<a name="line-131"></a> <span class='hs-keyglyph'>=></span> <span class='hs-layout'>(</span><span class='hs-keyword'>forall</span> <span class='hs-varid'>e</span><span class='hs-varop'>.</span> <span class='hs-conid'>Data</span> <span class='hs-varid'>e</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>e</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>m</span> <span class='hs-varid'>e</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-132"></a> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>m</span> <span class='hs-varid'>d</span><span class='hs-layout'>)</span>
<a name="line-133"></a><span class='hs-definition'>gmapAccumM</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>gfoldlAccum</span> <span class='hs-varid'>k</span> <span class='hs-varid'>z</span>
<a name="line-134"></a> <span class='hs-keyword'>where</span>
<a name="line-135"></a> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span> <span class='hs-varid'>c</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-varid'>a'</span><span class='hs-layout'>,</span><span class='hs-varid'>d'</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>f</span> <span class='hs-varid'>a</span> <span class='hs-varid'>d</span>
<a name="line-136"></a> <span class='hs-keyword'>in</span> <span class='hs-layout'>(</span><span class='hs-varid'>a'</span><span class='hs-layout'>,</span> <span class='hs-varid'>d'</span> <span class='hs-varop'>>>=</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>d''</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>c</span> <span class='hs-varop'>>>=</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>c'</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>return</span> <span class='hs-layout'>(</span><span class='hs-varid'>c'</span> <span class='hs-varid'>d''</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-137"></a> <span class='hs-varid'>z</span> <span class='hs-varid'>a</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>return</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span>
<a name="line-138"></a>
<a name="line-139"></a>
<a name="line-140"></a><a name="gmapAccumQl"></a><span class='hs-comment'>-- | gmapQl with accumulation</span>
<a name="line-141"></a><span class='hs-definition'>gmapAccumQl</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Data</span> <span class='hs-varid'>d</span>
<a name="line-142"></a> <span class='hs-keyglyph'>=></span> <span class='hs-layout'>(</span><span class='hs-varid'>r</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>r'</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>r</span><span class='hs-layout'>)</span>
<a name="line-143"></a> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>r</span>
<a name="line-144"></a> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-keyword'>forall</span> <span class='hs-varid'>e</span><span class='hs-varop'>.</span> <span class='hs-conid'>Data</span> <span class='hs-varid'>e</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>e</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>r'</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-145"></a> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>r</span><span class='hs-layout'>)</span>
<a name="line-146"></a><span class='hs-definition'>gmapAccumQl</span> <span class='hs-varid'>o</span> <span class='hs-varid'>r0</span> <span class='hs-varid'>f</span> <span class='hs-varid'>a0</span> <span class='hs-varid'>d0</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-varid'>a1</span><span class='hs-layout'>,</span> <span class='hs-varid'>r1</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>gfoldlAccum</span> <span class='hs-varid'>k</span> <span class='hs-varid'>z</span> <span class='hs-varid'>a0</span> <span class='hs-varid'>d0</span>
<a name="line-147"></a> <span class='hs-keyword'>in</span> <span class='hs-layout'>(</span><span class='hs-varid'>a1</span><span class='hs-layout'>,</span> <span class='hs-varid'>unCONST</span> <span class='hs-varid'>r1</span><span class='hs-layout'>)</span>
<a name="line-148"></a> <span class='hs-keyword'>where</span>
<a name="line-149"></a> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span> <span class='hs-layout'>(</span><span class='hs-conid'>CONST</span> <span class='hs-varid'>c</span><span class='hs-layout'>)</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-varid'>a'</span><span class='hs-layout'>,</span> <span class='hs-varid'>r</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>f</span> <span class='hs-varid'>a</span> <span class='hs-varid'>d</span>
<a name="line-150"></a> <span class='hs-keyword'>in</span> <span class='hs-layout'>(</span><span class='hs-varid'>a'</span><span class='hs-layout'>,</span> <span class='hs-conid'>CONST</span> <span class='hs-layout'>(</span><span class='hs-varid'>c</span> <span class='hs-varop'>`o`</span> <span class='hs-varid'>r</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-151"></a> <span class='hs-varid'>z</span> <span class='hs-varid'>a</span> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>CONST</span> <span class='hs-varid'>r0</span><span class='hs-layout'>)</span>
<a name="line-152"></a>
<a name="line-153"></a>
<a name="line-154"></a><a name="gmapAccumQr"></a><span class='hs-comment'>-- | gmapQr with accumulation</span>
<a name="line-155"></a><span class='hs-definition'>gmapAccumQr</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Data</span> <span class='hs-varid'>d</span>
<a name="line-156"></a> <span class='hs-keyglyph'>=></span> <span class='hs-layout'>(</span><span class='hs-varid'>r'</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>r</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>r</span><span class='hs-layout'>)</span>
<a name="line-157"></a> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>r</span>
<a name="line-158"></a> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-keyword'>forall</span> <span class='hs-varid'>e</span><span class='hs-varop'>.</span> <span class='hs-conid'>Data</span> <span class='hs-varid'>e</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>e</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>r'</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-159"></a> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>r</span><span class='hs-layout'>)</span>
<a name="line-160"></a><span class='hs-definition'>gmapAccumQr</span> <span class='hs-varid'>o</span> <span class='hs-varid'>r0</span> <span class='hs-varid'>f</span> <span class='hs-varid'>a0</span> <span class='hs-varid'>d0</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-varid'>a1</span><span class='hs-layout'>,</span> <span class='hs-varid'>l</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>gfoldlAccum</span> <span class='hs-varid'>k</span> <span class='hs-varid'>z</span> <span class='hs-varid'>a0</span> <span class='hs-varid'>d0</span>
<a name="line-161"></a> <span class='hs-keyword'>in</span> <span class='hs-layout'>(</span><span class='hs-varid'>a1</span><span class='hs-layout'>,</span> <span class='hs-varid'>unQr</span> <span class='hs-varid'>l</span> <span class='hs-varid'>r0</span><span class='hs-layout'>)</span>
<a name="line-162"></a> <span class='hs-keyword'>where</span>
<a name="line-163"></a> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span> <span class='hs-layout'>(</span><span class='hs-conid'>Qr</span> <span class='hs-varid'>c</span><span class='hs-layout'>)</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-varid'>a'</span><span class='hs-layout'>,</span><span class='hs-varid'>r'</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>f</span> <span class='hs-varid'>a</span> <span class='hs-varid'>d</span>
<a name="line-164"></a> <span class='hs-keyword'>in</span> <span class='hs-layout'>(</span><span class='hs-varid'>a'</span><span class='hs-layout'>,</span> <span class='hs-conid'>Qr</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>r</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>c</span> <span class='hs-layout'>(</span><span class='hs-varid'>r'</span> <span class='hs-varop'>`o`</span> <span class='hs-varid'>r</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-165"></a> <span class='hs-varid'>z</span> <span class='hs-varid'>a</span> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Qr</span> <span class='hs-varid'>id</span><span class='hs-layout'>)</span>
<a name="line-166"></a>
<a name="line-167"></a>
<a name="line-168"></a><a name="gmapAccumQ"></a><span class='hs-comment'>-- | gmapQ with accumulation</span>
<a name="line-169"></a><span class='hs-definition'>gmapAccumQ</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Data</span> <span class='hs-varid'>d</span>
<a name="line-170"></a> <span class='hs-keyglyph'>=></span> <span class='hs-layout'>(</span><span class='hs-keyword'>forall</span> <span class='hs-varid'>e</span><span class='hs-varop'>.</span> <span class='hs-conid'>Data</span> <span class='hs-varid'>e</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>e</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>q</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-171"></a> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>q</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>)</span>
<a name="line-172"></a><span class='hs-definition'>gmapAccumQ</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>gmapAccumQr</span> <span class='hs-layout'>(</span><span class='hs-conop'>:</span><span class='hs-layout'>)</span> <span class='hs-conid'>[]</span> <span class='hs-varid'>f</span>
<a name="line-173"></a>
<a name="line-174"></a>
<a name="line-175"></a>
<a name="line-176"></a><span class='hs-comment'>------------------------------------------------------------------------------</span>
<a name="line-177"></a><span class='hs-comment'>--</span>
<a name="line-178"></a><span class='hs-comment'>-- Helper type constructors</span>
<a name="line-179"></a><span class='hs-comment'>--</span>
<a name="line-180"></a><span class='hs-comment'>------------------------------------------------------------------------------</span>
<a name="line-181"></a>
<a name="line-182"></a>
<a name="line-183"></a><a name="ID"></a><span class='hs-comment'>-- | The identity type constructor needed for the definition of gmapAccumT</span>
<a name="line-184"></a><a name="ID"></a><span class='hs-keyword'>newtype</span> <span class='hs-conid'>ID</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>ID</span> <span class='hs-layout'>{</span> <span class='hs-varid'>unID</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>x</span> <span class='hs-layout'>}</span>
<a name="line-185"></a>
<a name="line-186"></a>
<a name="line-187"></a><a name="CONST"></a><span class='hs-comment'>-- | The constant type constructor needed for the definition of gmapAccumQl</span>
<a name="line-188"></a><a name="CONST"></a><span class='hs-keyword'>newtype</span> <span class='hs-conid'>CONST</span> <span class='hs-varid'>c</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>CONST</span> <span class='hs-layout'>{</span> <span class='hs-varid'>unCONST</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>c</span> <span class='hs-layout'>}</span>
<a name="line-189"></a>
<a name="line-190"></a>
<a name="line-191"></a><a name="Qr"></a><span class='hs-comment'>-- | The type constructor needed for the definition of gmapAccumQr</span>
<a name="line-192"></a><a name="Qr"></a><span class='hs-keyword'>newtype</span> <span class='hs-conid'>Qr</span> <span class='hs-varid'>r</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Qr</span> <span class='hs-layout'>{</span> <span class='hs-varid'>unQr</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>r</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>r</span> <span class='hs-layout'>}</span>
<a name="line-193"></a>
<a name="line-194"></a>
<a name="line-195"></a>
<a name="line-196"></a><span class='hs-comment'>------------------------------------------------------------------------------</span>
<a name="line-197"></a><span class='hs-comment'>--</span>
<a name="line-198"></a><span class='hs-comment'>-- Mapping combinators for twin traversal</span>
<a name="line-199"></a><span class='hs-comment'>--</span>
<a name="line-200"></a><span class='hs-comment'>------------------------------------------------------------------------------</span>
<a name="line-201"></a>
<a name="line-202"></a>
<a name="line-203"></a><a name="gzipWithT"></a><span class='hs-comment'>-- | Twin map for transformation</span>
<a name="line-204"></a><span class='hs-definition'>gzipWithT</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>GenericQ</span> <span class='hs-layout'>(</span><span class='hs-conid'>GenericT</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>GenericQ</span> <span class='hs-layout'>(</span><span class='hs-conid'>GenericT</span><span class='hs-layout'>)</span>
<a name="line-205"></a><span class='hs-definition'>gzipWithT</span> <span class='hs-varid'>f</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>case</span> <span class='hs-varid'>gmapAccumT</span> <span class='hs-varid'>perkid</span> <span class='hs-varid'>funs</span> <span class='hs-varid'>y</span> <span class='hs-keyword'>of</span>
<a name="line-206"></a> <span class='hs-layout'>(</span><span class='hs-conid'>[]</span><span class='hs-layout'>,</span> <span class='hs-varid'>c</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>c</span>
<a name="line-207"></a> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>error</span> <span class='hs-str'>"gzipWithT"</span>
<a name="line-208"></a> <span class='hs-keyword'>where</span>
<a name="line-209"></a> <span class='hs-varid'>perkid</span> <span class='hs-varid'>a</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>tail</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>unGT</span> <span class='hs-layout'>(</span><span class='hs-varid'>head</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-varid'>d</span><span class='hs-layout'>)</span>
<a name="line-210"></a> <span class='hs-varid'>funs</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>gmapQ</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>k</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>GT</span> <span class='hs-layout'>(</span><span class='hs-varid'>f</span> <span class='hs-varid'>k</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>x</span>
<a name="line-211"></a>
<a name="line-212"></a>
<a name="line-213"></a>
<a name="line-214"></a><a name="gzipWithM"></a><span class='hs-comment'>-- | Twin map for monadic transformation</span>
<a name="line-215"></a><span class='hs-definition'>gzipWithM</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Monad</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>GenericQ</span> <span class='hs-layout'>(</span><span class='hs-conid'>GenericM</span> <span class='hs-varid'>m</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>GenericQ</span> <span class='hs-layout'>(</span><span class='hs-conid'>GenericM</span> <span class='hs-varid'>m</span><span class='hs-layout'>)</span>
<a name="line-216"></a><span class='hs-definition'>gzipWithM</span> <span class='hs-varid'>f</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>case</span> <span class='hs-varid'>gmapAccumM</span> <span class='hs-varid'>perkid</span> <span class='hs-varid'>funs</span> <span class='hs-varid'>y</span> <span class='hs-keyword'>of</span>
<a name="line-217"></a> <span class='hs-layout'>(</span><span class='hs-conid'>[]</span><span class='hs-layout'>,</span> <span class='hs-varid'>c</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>c</span>
<a name="line-218"></a> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>error</span> <span class='hs-str'>"gzipWithM"</span>
<a name="line-219"></a> <span class='hs-keyword'>where</span>
<a name="line-220"></a> <span class='hs-varid'>perkid</span> <span class='hs-varid'>a</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>tail</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>unGM</span> <span class='hs-layout'>(</span><span class='hs-varid'>head</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-varid'>d</span><span class='hs-layout'>)</span>
<a name="line-221"></a> <span class='hs-varid'>funs</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>gmapQ</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>k</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>GM</span> <span class='hs-layout'>(</span><span class='hs-varid'>f</span> <span class='hs-varid'>k</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>x</span>
<a name="line-222"></a>
<a name="line-223"></a>
<a name="line-224"></a><a name="gzipWithQ"></a><span class='hs-comment'>-- | Twin map for queries</span>
<a name="line-225"></a><span class='hs-definition'>gzipWithQ</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>GenericQ</span> <span class='hs-layout'>(</span><span class='hs-conid'>GenericQ</span> <span class='hs-varid'>r</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>GenericQ</span> <span class='hs-layout'>(</span><span class='hs-conid'>GenericQ</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>r</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>)</span>
<a name="line-226"></a><span class='hs-definition'>gzipWithQ</span> <span class='hs-varid'>f</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>case</span> <span class='hs-varid'>gmapAccumQ</span> <span class='hs-varid'>perkid</span> <span class='hs-varid'>funs</span> <span class='hs-varid'>y</span> <span class='hs-keyword'>of</span>
<a name="line-227"></a> <span class='hs-layout'>(</span><span class='hs-conid'>[]</span><span class='hs-layout'>,</span> <span class='hs-varid'>r</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>r</span>
<a name="line-228"></a> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>error</span> <span class='hs-str'>"gzipWithQ"</span>
<a name="line-229"></a> <span class='hs-keyword'>where</span>
<a name="line-230"></a> <span class='hs-varid'>perkid</span> <span class='hs-varid'>a</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>tail</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>unGQ</span> <span class='hs-layout'>(</span><span class='hs-varid'>head</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-varid'>d</span><span class='hs-layout'>)</span>
<a name="line-231"></a> <span class='hs-varid'>funs</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>gmapQ</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>k</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>GQ</span> <span class='hs-layout'>(</span><span class='hs-varid'>f</span> <span class='hs-varid'>k</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>x</span>
<a name="line-232"></a>
<a name="line-233"></a>
<a name="line-234"></a>
<a name="line-235"></a><span class='hs-comment'>------------------------------------------------------------------------------</span>
<a name="line-236"></a><span class='hs-comment'>--</span>
<a name="line-237"></a><span class='hs-comment'>-- Typical twin traversals</span>
<a name="line-238"></a><span class='hs-comment'>--</span>
<a name="line-239"></a><span class='hs-comment'>------------------------------------------------------------------------------</span>
<a name="line-240"></a>
<a name="line-241"></a><a name="geq"></a><span class='hs-comment'>-- | Generic equality: an alternative to \"deriving Eq\"</span>
<a name="line-242"></a><span class='hs-definition'>geq</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Data</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
<a name="line-243"></a>
<a name="line-244"></a><span class='hs-comment'>{-
<a name="line-245"></a>
<a name="line-246"></a>Testing for equality of two terms goes like this. Firstly, we
<a name="line-247"></a>establish the equality of the two top-level datatype
<a name="line-248"></a>constructors. Secondly, we use a twin gmap combinator, namely tgmapQ,
<a name="line-249"></a>to compare the two lists of immediate subterms.
<a name="line-250"></a>
<a name="line-251"></a>(Note for the experts: the type of the worker geq' is rather general
<a name="line-252"></a>but precision is recovered via the restrictive type of the top-level
<a name="line-253"></a>operation geq. The imprecision of geq' is caused by the type system's
<a name="line-254"></a>unability to express the type equivalence for the corresponding
<a name="line-255"></a>couples of immediate subterms from the two given input terms.)
<a name="line-256"></a>
<a name="line-257"></a>-}</span>
<a name="line-258"></a>
<a name="line-259"></a><span class='hs-definition'>geq</span> <span class='hs-varid'>x0</span> <span class='hs-varid'>y0</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>geq'</span> <span class='hs-varid'>x0</span> <span class='hs-varid'>y0</span>
<a name="line-260"></a> <span class='hs-keyword'>where</span>
<a name="line-261"></a> <span class='hs-varid'>geq'</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>GenericQ</span> <span class='hs-layout'>(</span><span class='hs-conid'>GenericQ</span> <span class='hs-conid'>Bool</span><span class='hs-layout'>)</span>
<a name="line-262"></a> <span class='hs-varid'>geq'</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>toConstr</span> <span class='hs-varid'>x</span> <span class='hs-varop'>==</span> <span class='hs-varid'>toConstr</span> <span class='hs-varid'>y</span><span class='hs-layout'>)</span>
<a name="line-263"></a> <span class='hs-varop'>&&</span> <span class='hs-varid'>and</span> <span class='hs-layout'>(</span><span class='hs-varid'>gzipWithQ</span> <span class='hs-varid'>geq'</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span><span class='hs-layout'>)</span>
<a name="line-264"></a>
<a name="line-265"></a>
<a name="line-266"></a><a name="gzip"></a><span class='hs-comment'>-- | Generic zip controlled by a function with type-specific branches</span>
<a name="line-267"></a><span class='hs-definition'>gzip</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>GenericQ</span> <span class='hs-layout'>(</span><span class='hs-conid'>GenericM</span> <span class='hs-conid'>Maybe</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>GenericQ</span> <span class='hs-layout'>(</span><span class='hs-conid'>GenericM</span> <span class='hs-conid'>Maybe</span><span class='hs-layout'>)</span>
<a name="line-268"></a><span class='hs-comment'>-- See testsuite/.../Generics/gzip.hs for an illustration</span>
<a name="line-269"></a><span class='hs-definition'>gzip</span> <span class='hs-varid'>f</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span> <span class='hs-keyglyph'>=</span>
<a name="line-270"></a> <span class='hs-varid'>f</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span>
<a name="line-271"></a> <span class='hs-varop'>`orElse`</span>
<a name="line-272"></a> <span class='hs-keyword'>if</span> <span class='hs-varid'>toConstr</span> <span class='hs-varid'>x</span> <span class='hs-varop'>==</span> <span class='hs-varid'>toConstr</span> <span class='hs-varid'>y</span>
<a name="line-273"></a> <span class='hs-keyword'>then</span> <span class='hs-varid'>gzipWithM</span> <span class='hs-layout'>(</span><span class='hs-varid'>gzip</span> <span class='hs-varid'>f</span><span class='hs-layout'>)</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span>
<a name="line-274"></a> <span class='hs-keyword'>else</span> <span class='hs-conid'>Nothing</span>
<a name="line-275"></a>
<a name="line-276"></a><a name="gcompare"></a><span class='hs-comment'>-- | Generic comparison: an alternative to \"deriving Ord\"</span>
<a name="line-277"></a><span class='hs-definition'>gcompare</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Data</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Ordering</span>
<a name="line-278"></a><span class='hs-definition'>gcompare</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>gcompare'</span>
<a name="line-279"></a> <span class='hs-keyword'>where</span>
<a name="line-280"></a> <span class='hs-varid'>gcompare'</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-conid'>Data</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Data</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Ordering</span>
<a name="line-281"></a> <span class='hs-varid'>gcompare'</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span>
<a name="line-282"></a> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>let</span> <span class='hs-varid'>repX</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>constrRep</span> <span class='hs-varop'>$</span> <span class='hs-varid'>toConstr</span> <span class='hs-varid'>x</span>
<a name="line-283"></a> <span class='hs-varid'>repY</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>constrRep</span> <span class='hs-varop'>$</span> <span class='hs-varid'>toConstr</span> <span class='hs-varid'>y</span>
<a name="line-284"></a> <span class='hs-keyword'>in</span>
<a name="line-285"></a> <span class='hs-keyword'>case</span> <span class='hs-layout'>(</span><span class='hs-varid'>repX</span><span class='hs-layout'>,</span> <span class='hs-varid'>repY</span><span class='hs-layout'>)</span> <span class='hs-keyword'>of</span>
<a name="line-286"></a> <span class='hs-layout'>(</span><span class='hs-conid'>AlgConstr</span> <span class='hs-varid'>nX</span><span class='hs-layout'>,</span> <span class='hs-conid'>AlgConstr</span> <span class='hs-varid'>nY</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span>
<a name="line-287"></a> <span class='hs-varid'>nX</span> <span class='hs-varop'>`compare`</span> <span class='hs-varid'>nY</span> <span class='hs-varop'>`mappend`</span> <span class='hs-varid'>mconcat</span> <span class='hs-layout'>(</span><span class='hs-varid'>gzipWithQ</span> <span class='hs-varid'>gcompare'</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span><span class='hs-layout'>)</span>
<a name="line-288"></a> <span class='hs-layout'>(</span><span class='hs-conid'>IntConstr</span> <span class='hs-varid'>iX</span><span class='hs-layout'>,</span> <span class='hs-conid'>IntConstr</span> <span class='hs-varid'>iY</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>iX</span> <span class='hs-varop'>`compare`</span> <span class='hs-varid'>iY</span>
<a name="line-289"></a> <span class='hs-layout'>(</span><span class='hs-conid'>FloatConstr</span> <span class='hs-varid'>rX</span><span class='hs-layout'>,</span> <span class='hs-conid'>FloatConstr</span> <span class='hs-varid'>rY</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>rX</span> <span class='hs-varop'>`compare`</span> <span class='hs-varid'>rY</span>
<a name="line-290"></a> <span class='hs-layout'>(</span><span class='hs-conid'>CharConstr</span> <span class='hs-varid'>cX</span><span class='hs-layout'>,</span> <span class='hs-conid'>CharConstr</span> <span class='hs-varid'>cY</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>cX</span> <span class='hs-varop'>`compare`</span> <span class='hs-varid'>cY</span>
<a name="line-291"></a> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>error</span> <span class='hs-str'>"type incompatibility in gcompare"</span>
</pre></body>
</html>
|