Ticket #64: show-read-Char-Word8.dpatch

File show-read-Char-Word8.dpatch, 15.1 kB (added by basvandijk, 20 months ago)
Line 
11 patch for repository http://code.haskell.org/vector:
2
3Fri Oct 14 15:47:45 CEST 2011  Bas van Dijk <v.dijk.bas@gmail.com>
4  * Define specific Show and Read instances for vectors of Chars and Word8s that show and read like Strings
5
6New patches:
7
8[Define specific Show and Read instances for vectors of Chars and Word8s that show and read like Strings
9Bas van Dijk <v.dijk.bas@gmail.com>**20111014134745
10 Ignore-this: 4f1fa503f2f9ffd58c38ce021c7dd3cf
11] {
12hunk ./Data/Vector.hs 1
13-{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, TypeFamilies, Rank2Types #-}
14+{-# LANGUAGE FlexibleInstances
15+           , MultiParamTypeClasses
16+           , TypeFamilies
17+           , Rank2Types
18+           , OverlappingInstances
19+  #-}
20 
21 -- |
22 -- Module      : Data.Vector
23hunk ./Data/Vector.hs 187
24 import Data.Typeable ( Typeable )
25 import Data.Data     ( Data(..) )
26 import Text.Read     ( Read(..), readListPrecDefault )
27+import Data.Word     ( Word8 )
28 
29 import Data.Monoid   ( Monoid(..) )
30 import qualified Control.Applicative as Applicative
31hunk ./Data/Vector.hs 194
32 import qualified Data.Foldable as Foldable
33 import qualified Data.Traversable as Traversable
34 
35+
36 -- | Boxed vectors, supporting efficient slicing.
37 data Vector a = Vector {-# UNPACK #-} !Int
38                        {-# UNPACK #-} !Int
39hunk ./Data/Vector.hs 204
40 instance Show a => Show (Vector a) where
41   showsPrec = G.showsPrec
42 
43+instance Show (Vector Char) where
44+  showsPrec = G.showsPrecChar
45+
46+instance Show (Vector Word8) where
47+  showsPrec = G.showsPrecWord8
48+
49 instance Read a => Read (Vector a) where
50   readPrec = G.readPrec
51   readListPrec = readListPrecDefault
52hunk ./Data/Vector.hs 214
53 
54+instance Read (Vector Char) where
55+  readPrec = G.readPrecChar
56+
57+instance Read (Vector Word8) where
58+  readPrec = G.readPrecWord8
59+
60 instance Data a => Data (Vector a) where
61   gfoldl       = G.gfoldl
62   toConstr _   = error "toConstr"
63hunk ./Data/Vector/Generic.hs 157
64   eq, cmp,
65 
66   -- ** Show and Read
67-  showsPrec, readPrec,
68+  showsPrec,      readPrec,
69+  showsPrecChar,  readPrecChar,
70+  showsPrecWord8, readPrecWord8,
71 
72   -- ** @Data@ and @Typeable@
73   gfoldl, dataCast, mkType
74hunk ./Data/Vector/Generic.hs 198
75                         mapM, mapM_, sequence, sequence_,
76                         showsPrec )
77 
78+import qualified Text.Show ( showsPrec )
79+
80 import qualified Text.Read as Read
81hunk ./Data/Vector/Generic.hs 201
82+import Data.Functor ( (<$>) )
83+import Data.Word    ( Word8 )
84+import Data.Char    ( ord )
85+import GHC.Base     ( unsafeChr )
86+
87 import Data.Typeable ( Typeable1, gcast1 )
88 
89 #include "vector.h"
90hunk ./Data/Vector/Generic.hs 2007
91 {-# INLINE showsPrec #-}
92 showsPrec p v = showParen (p > 10) $ showString "fromList " . shows (toList v)
93 
94+-- | Generic definition of 'Prelude.showsPrec'
95+-- but shows the vector as a 'String'.
96+showsPrecChar :: (Vector v Char) => Int -> v Char -> ShowS
97+{-# INLINE showsPrecChar #-}
98+showsPrecChar p v = Text.Show.showsPrec p (toList v)
99+
100+-- | Generic definition of 'Prelude.showsPrec'
101+-- but shows the vector of @'Word8's@ as a 'String'.
102+showsPrecWord8 :: (Vector v Word8, Vector v Char) => Int -> v Word8 -> ShowS
103+{-# INLINE showsPrecWord8 #-}
104+showsPrecWord8 p = showsPrecChar p . map w2c
105+
106+-- | Conversion between 'Word8' and 'Char'. Should compile to a no-op.
107+w2c :: Word8 -> Char
108+w2c = unsafeChr . fromIntegral
109+{-# INLINE w2c #-}
110+
111+-- | Unsafe conversion between 'Char' and 'Word8'. This is a no-op and
112+-- silently truncates to 8 bits Chars > '\255'.
113+c2w :: Char -> Word8
114+c2w = fromIntegral . ord
115+{-# INLINE c2w #-}
116+
117+-- | Generic definition of 'Text.Read.readPrec'
118+-- but reads to vector as a 'String'.
119+readPrecChar :: (Vector v Char) => Read.ReadPrec (v Char)
120+{-# INLINE readPrecChar #-}
121+readPrecChar = fromList <$> Read.readPrec
122+
123+-- | Generic definition of 'Text.Read.readPrec'
124+-- but reads to vector of @'Word8's@ as a 'String'.
125+--
126+-- Silently truncates to 8 bits Chars > '\255'.
127+readPrecWord8 :: (Vector v Word8, Vector v Char) => Read.ReadPrec (v Word8)
128+{-# INLINE readPrecWord8 #-}
129+readPrecWord8 = map c2w <$> readPrecChar
130+
131 -- | Generic definition of 'Text.Read.readPrec'
132 readPrec :: (Vector v a, Read a) => Read.ReadPrec (v a)
133 {-# INLINE readPrec #-}
134hunk ./Data/Vector/Generic.hs 2049
135 readPrec = Read.parens $ Read.prec 10 $ do
136   Read.Ident "fromList" <- Read.lexP
137-  xs <- Read.readPrec
138-  return (fromList xs)
139+  fromList <$> Read.readPrec
140 
141 -- Data and Typeable
142 -- -----------------
143hunk ./Data/Vector/Primitive.hs 1
144-{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, TypeFamilies, ScopedTypeVariables, Rank2Types #-}
145+{-# LANGUAGE FlexibleInstances
146+           , MultiParamTypeClasses
147+           , TypeFamilies
148+           , ScopedTypeVariables
149+           , Rank2Types
150+           , OverlappingInstances
151+  #-}
152 
153 -- |
154 -- Module      : Data.Vector.Primitive
155hunk ./Data/Vector/Primitive.hs 171
156 
157 import Data.Typeable ( Typeable )
158 import Data.Data     ( Data(..) )
159+import Data.Word     ( Word8 )
160 import Text.Read     ( Read(..), readListPrecDefault )
161 
162 import Data.Monoid   ( Monoid(..) )
163hunk ./Data/Vector/Primitive.hs 185
164 instance (Show a, Prim a) => Show (Vector a) where
165   showsPrec = G.showsPrec
166 
167+instance Show (Vector Char) where
168+  showsPrec = G.showsPrecChar
169+
170+instance Show (Vector Word8) where
171+  showsPrec = G.showsPrecWord8
172+
173 instance (Read a, Prim a) => Read (Vector a) where
174   readPrec = G.readPrec
175   readListPrec = readListPrecDefault
176hunk ./Data/Vector/Primitive.hs 195
177 
178+instance Read (Vector Char) where
179+  readPrec = G.readPrecChar
180+
181+instance Read (Vector Word8) where
182+  readPrec = G.readPrecWord8
183+
184 instance (Data a, Prim a) => Data (Vector a) where
185   gfoldl       = G.gfoldl
186   toConstr _   = error "toConstr"
187hunk ./Data/Vector/Storable.hs 1
188-{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, TypeFamilies, Rank2Types, ScopedTypeVariables #-}
189+{-# LANGUAGE MultiParamTypeClasses
190+           , FlexibleInstances
191+           , TypeFamilies
192+           , Rank2Types
193+           , ScopedTypeVariables
194+           , OverlappingInstances
195+  #-}
196 
197 -- |
198 -- Module      : Data.Vector.Storable
199hunk ./Data/Vector/Storable.hs 176
200 
201 import Data.Typeable ( Typeable )
202 import Data.Data     ( Data(..) )
203+import Data.Word     ( Word8 )
204 import Text.Read     ( Read(..), readListPrecDefault )
205 
206 import Data.Monoid   ( Monoid(..) )
207hunk ./Data/Vector/Storable.hs 191
208 instance (Show a, Storable a) => Show (Vector a) where
209   showsPrec = G.showsPrec
210 
211+instance Show (Vector Char) where
212+  showsPrec = G.showsPrecChar
213+
214+instance Show (Vector Word8) where
215+  showsPrec = G.showsPrecWord8
216+
217 instance (Read a, Storable a) => Read (Vector a) where
218   readPrec = G.readPrec
219   readListPrec = readListPrecDefault
220hunk ./Data/Vector/Storable.hs 201
221 
222+instance Read (Vector Char) where
223+  readPrec = G.readPrecChar
224+
225+instance Read (Vector Word8) where
226+  readPrec = G.readPrecWord8
227+
228 instance (Data a, Storable a) => Data (Vector a) where
229   gfoldl       = G.gfoldl
230   toConstr _   = error "toConstr"
231hunk ./Data/Vector/Unboxed.hs 1
232-{-# LANGUAGE Rank2Types #-}
233+{-# LANGUAGE Rank2Types, FlexibleInstances, OverlappingInstances #-}
234 
235 -- |
236 -- Module      : Data.Vector.Unboxed
237hunk ./Data/Vector/Unboxed.hs 191
238 
239 import Data.Monoid   ( Monoid(..) )
240 
241+import Data.Word     ( Word8 )
242+
243 #include "vector.h"
244 
245 -- See http://trac.haskell.org/vector/ticket/12
246hunk ./Data/Vector/Unboxed.hs 233
247 instance (Show a, Unbox a) => Show (Vector a) where
248   showsPrec = G.showsPrec
249 
250+instance Show (Vector Char) where
251+  showsPrec = G.showsPrecChar
252+
253+instance Show (Vector Word8) where
254+  showsPrec = G.showsPrecWord8
255+
256 instance (Read a, Unbox a) => Read (Vector a) where
257   readPrec = G.readPrec
258   readListPrec = readListPrecDefault
259hunk ./Data/Vector/Unboxed.hs 243
260 
261+instance Read (Vector Char) where
262+  readPrec = G.readPrecChar
263+
264+instance Read (Vector Word8) where
265+  readPrec = G.readPrecWord8
266+
267 -- Length information
268 -- ------------------
269 
270}
271
272Context:
273
274[Added RULES that translates "unsafeFromForeignPtr fp 0 n" to "unsafeFromForeignPtr0 fp n"
275Bas van Dijk <v.dijk.bas@gmail.com>**20110930134731
276 Ignore-this: 7ca5f9f0a7515d2208464ecff411b0b6
277]
278[Add unsafeFromForeignPtr0 and unsafeToForeignPtr0 to Data.Vector.Storable.Mutable
279Bas van Dijk <v.dijk.bas@gmail.com>**20110930082125
280 Ignore-this: e2cb96f3f32c6b220c9553dcd65872b1
281]
282[Add unsafeFromForeignPtr0 and unsafeToForeignPtr0 to Data.Vector.Storable
283Bas van Dijk <v.dijk.bas@gmail.com>**20110930081100
284 Ignore-this: 427d2d410cf5c64cbec429337e1c3e8e
285]
286[Bump version
287Roman Leshchinskiy <rl@cse.unsw.edu.au>**20111013204447
288 Ignore-this: a4117a951aa79211f1991331d73f4e11
289]
290[Changelog
291Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110830193201
292 Ignore-this: 6a72e542a0132600af9b4a1290c5ebc9
293]
294[Require primitive-0.4.0.1
295Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110830193147
296 Ignore-this: de70696c2fa670f5d5a50b732827800a
297]
298[Bump version number
299Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110830193136
300 Ignore-this: a4f64c244b926d6e14df34912af8e32e
301]
302[Add construct and constructN to Safe modules
303Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110830192509
304 Ignore-this: 45c293fbcf754ed87badb179a335f762
305]
306[Add MonadPlus instance
307Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110830192347
308 Ignore-this: 5d1b36db855beaf9092107f60d3f7ed6
309]
310[TAG 0.8
311Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110829001717
312 Ignore-this: b997d863aaacb77b8bf1ff653b42e096
313]
314[Add tests
315Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110829001208
316 Ignore-this: 23b8ae73433bdfc761c9f0657b1a09c7
317]
318[Follow changes in primitive
319Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110828104527
320 Ignore-this: 5a7db808ef443772b3b08f63b990ff03
321]
322[Export mstream and mstreamR
323Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110828102107
324 Ignore-this: fb7bea8de613bbc4bf71f0b8c661959b
325]
326[Fix leftover conflicts
327Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110827232146
328 Ignore-this: 5199073ea0d577b9860bceb6f75fd73f
329]
330[Resolve conflict with stray patch
331Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110827231817
332 Ignore-this: a81fd1a56855d96ce9d0eff991202c93
333]
334[Bump versions of vector-tests
335benl@ouroborus.net**20101014033852
336 Ignore-this: 1b6bf632d2b41e5cdc2af34d6298cda4
337]
338[Improve package description
339Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110826232244
340 Ignore-this: ceda9feab9d7f204c3f0b11267aaf10
341]
342[Improve comments
343Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110826232209
344 Ignore-this: fe01df034e4223beadfb3f5ded6fe4
345]
346[Mention Safe modules in the package description
347Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110826231210
348 Ignore-this: 2ef9ec43b0cd5d2186327bec8266b0f0
349]
350[Change comments in Safe modules
351Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110826230756
352 Ignore-this: 9394772711908bf11c7ef28f58a60afa
353]
354[Bump version to 0.8
355Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110826223236
356 Ignore-this: 44c3a02908b6c6dbb0c3eae9fe7a5e36
357]
358[Use mkTyCon3 if available
359Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110826222802
360 Ignore-this: 115558d92fd394c770a8194361040538
361]
362[Changelog
363Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110826220930
364 Ignore-this: 26017ef444b4f753d59577eb23146f45
365]
366[Follow containers convention in Show instances and add Read instances
367Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110826220427
368 Ignore-this: 68484ab3169284a999f929b40a1a9130
369]
370[Changelog
371Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110825221128
372 Ignore-this: 5a37d7777b001ef7985f571b341a5648
373]
374[Build tests with -O0 and -O2
375Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110825215522
376 Ignore-this: 1faf722013f49ab58b04f6169c844cc2
377]
378[Add tests
379Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110825214948
380 Ignore-this: 2bada88c9462216ac23a8c1403649a92
381]
382[Reorganise tests
383Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110825213103
384 Ignore-this: cdb4f7ac54e93ca97195211e8cf3cb1f
385]
386[Changelog
387Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110825212324
388 Ignore-this: a2da154060c2962c2d4805b67996b03d
389]
390[Slightly faster version of concatMap
391Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110823224759
392 Ignore-this: 9575c568c957a95ca915d763014850cf
393]
394[Add a seq
395Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110823224750
396 Ignore-this: 37a1fc9ad603c7f24e5a310460933021
397]
398[Add tests for constructN and constructrN
399Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110819234335
400 Ignore-this: 4c24a192cffc8d7a71ba35cdbb543646
401]
402[Add constructN and constructrN
403Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110819234052
404 Ignore-this: 2416015edb789cddfc871d6a64bfe2b2
405]
406[Significantly improve basicSet (based on a patch by Louis Wasserman)
407Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110819223644
408 Ignore-this: 57a0c44481c4be66be5fbf70ddda2262
409]
410[Make thaw and unsafeThaw fusible
411Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110819215440
412 Ignore-this: d616612bd7b9b8733de6024c25a94416
413]
414[Add New.runPrim
415Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110819215420
416 Ignore-this: 5561cf4699f2e7718a0e940f085bc843
417]
418[Fix Safe Haskell modules on 7.2.1
419Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110819211846
420 Ignore-this: 9ee149f27925315fa8e443be882e7590
421]
422[Fuse reverse
423Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110818223155
424 Ignore-this: f63eb849684f5222de0ad0ecb3788654
425]
426[Fix fixity of (!!) and (!)
427Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110818222159
428 Ignore-this: 56a1348b61bfa3a75c76cc5e09592f4f
429]
430[Add (!?) for streams and make vector (!?) fusible
431Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110818222115
432 Ignore-this: 2a2c8801263922e40f77c3e1c03b9c3b
433]
434[Use the Addr# field in ForeignPtr for Storable vectors
435Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110818221206
436 Ignore-this: 4f162bff1ee98a5e982e046b0390355a
437]
438[Fix vector-tests.cabal
439Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110818220827
440 Ignore-this: 374a276c4c6fedc2add8a16c8a7880b8
441]
442[Remove deprecated functions
443Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110817224752
444 Ignore-this: b56b391e56bead2c158206c637504c14
445]
446[Changelog
447Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110817223740
448 Ignore-this: 4c65899a91ceccb369303a581509c719
449]
450[Use new array copying primitives
451Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110817222820
452 Ignore-this: 2944ee055836be9d67f91d005a9659e8
453]
454[Require primitive 0.4 and replace deprecated primitives
455Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110817222319
456 Ignore-this: 5bb273bdacd1fcc73c33c880c9622772
457]
458[Changelog
459Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110812105754
460 Ignore-this: e389c2fbff8e58829d2cbedec9d55989
461]
462[Relax dependencies
463Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110812105641
464 Ignore-this: 791bab1d9c3d73390cbe243753e5f4df
465]
466[Expose Safe Haskell modules
467Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110812105555
468 Ignore-this: 2e2744f74e368bbf83ea73d922afcd9f
469]
470[Use Safe Haskell if GHC >= 7.2
471David Terei <davidterei@gmail.com>**20110812000540
472 Ignore-this: 404916c12b0079e5e42f9747fb502146
473]
474[Add instances for Monad, Applicative, Alternative, Foldable, Traversable
475Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110625093340
476 Ignore-this: 85f0e0b956099e3fcd1ac97317ae980c
477]
478[Add Functor instance for boxed vectors
479Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110623200603
480 Ignore-this: 8038c069d2a48fe827f62f332cce8a60
481]
482[Bump version number
483Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110623200416
484 Ignore-this: 3bf5875a1678331a26b06279a9a5d556
485]
486[TAG 0.7.1
487Roman Leshchinskiy <rl@cse.unsw.edu.au>**20110618225609
488 Ignore-this: 77ab304a0004a9e7038952644a62cb4
489]
490Patch bundle hash:
49160a677bb0f66c1b1dcfede7f8ff93ec136213564