Ticket #64: IsString.dpatch

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