Ticket #3453: check

File check, 10.3 KB (added by JonFairbairn, 4 years ago)

darcs patch on base

Line 
1Sun Aug 23 09:46:11 BST 2009  jon.fairbairn@cl.cam.ac.uk
2  * Add MonadPlus check function
3  Generalisation of guard. Of use in writing functions such as this:
4 
5  readMaybe :: Read a => String -> Maybe a
6  readMaybe
7      = join . fmap no_trailing_garbage . listToMaybe . reads
8        where no_trailing_garbage = fmap fst . check (all isSpace . snd)
9 
10
11New patches:
12
13[Add MonadPlus check function
14jon.fairbairn@cl.cam.ac.uk**20090823084611
15 Ignore-this: 34c8e9768f9cbb9512f207d357fb587d
16 Generalisation of guard. Of use in writing functions such as this:
17 
18 readMaybe :: Read a => String -> Maybe a
19 readMaybe
20     = join . fmap no_trailing_garbage . listToMaybe . reads
21       where no_trailing_garbage = fmap fst . check (all isSpace . snd)
22 
23] {
24hunk ./Control/Monad.hs 60
25     -- ** Conditional execution of monadic expressions
26 
27     , guard         -- :: (MonadPlus m) => Bool -> m ()
28+    , check         -- :: (MonadPlus m) => (a -> Bool) -> a -> m a
29     , when          -- :: (Monad m) => Bool -> m () -> m ()
30     , unless        -- :: (Monad m) => Bool -> m () -> m ()
31 
32hunk ./Control/Monad.hs 269
33 unless            :: (Monad m) => Bool -> m () -> m ()
34 unless p s        =  if p then return () else s
35 
36+{- | conditional injection into a MonadPlus
37+
38+generalisation of @guard@:
39+takes a predicate and an item and returns the item if the
40+predicate is true for that item. For example
41+
42+> check (not . isSpace) c :: Maybe Char
43+
44+will return @Just c@ if @c@ is not a space, or @Nothing@ otherwise
45+
46+-}
47+check :: (MonadPlus m) => (a -> Bool) -> a -> m a
48+check p a
49+    | p a = return a
50+    | otherwise = mzero
51+-- we expect these to be true:
52+-- guard == flip (check . const)
53+-- List.filter = (concat .) . map . check
54+-- which suggests that
55+-- (join .) . liftM . check :: (MonadPlus m) => (a1 -> Bool) -> m a1 -> m a1
56+-- is an interesting function, call it mfilter; now
57+-- check p == mfilter p . return
58+
59 -- | Promote a function to a monad.
60 liftM   :: (Monad m) => (a1 -> r) -> m a1 -> m r
61 liftM f m1              = do { x1 <- m1; return (f x1) }
62}
63
64Context:
65
66[Apply fix for #1548, from squadette@gmail.com
67Simon Marlow <marlowsd@gmail.com>**20090819120700
68 Ignore-this: 31c237c46a6445f588ed4b8c51bb6231
69]
70[improvements to Data.Fixed: instances for Typeable and Data, more predefined types
71Ashley Yakeley <ashley@semantic.org>**20090812055058
72 Ignore-this: feeece36d5632f02a05d137d2a39ab78
73]
74[Fix "Cabal check" warnings
75Ian Lynagh <igloo@earth.li>**20090811215856]
76[Add a GHC.Constants module; fixes trac #3094
77Ian Lynagh <igloo@earth.li>**20090809183252]
78[Apply proposal #3393
79Ian Lynagh <igloo@earth.li>**20090809134717
80 Add openTempFileWithDefaultPermissions and
81 openBinaryTempFileWithDefaultPermissions.
82]
83[Add some more C wrappers; patch from Krister Walfridsson
84Ian Lynagh <igloo@earth.li>**20090807200631
85 Fixes 21 testsuite errors on NetBSD 5.99.
86]
87[Fixing configure for autoconf 2.64
88Alexander Dunlap <alexander.dunlap@gmail.com>**20090805060748
89 Ignore-this: 992ab91ae3d68c12dbb265776e33e243
90]
91[add INLINE toList
92Ross Paterson <ross@soi.city.ac.uk>**20090806142853
93 Ignore-this: aba16aabb17d5dca44f15d188945680e
94 
95 In anticipation of the fixing of #2353.
96]
97[fix a copyright
98Simon Marlow <marlowsd@gmail.com>**20090805134045
99 Ignore-this: b0ffbdd38fbba121e8bcba37c4082a60
100]
101[Tweak the BufferedIO class to enable a memory-mapped file implementation
102Simon Marlow <marlowsd@gmail.com>**20090805134036
103 Ignore-this: ec67d7a0a6d977438deaa342503f77e0
104 We have to eliminate the assumption that an empty write buffer can be
105 constructed by setting the buffer pointers to zero: this isn't
106 necessarily the case when the buffer corresponds to a memory-mapped
107 file, or other in-memory device implementation.
108]
109[Deprecate Control.OldException
110Ian Lynagh <igloo@earth.li>**20090804143910]
111[Windows build fix, following RTS tidyup
112Simon Marlow <marlowsd@gmail.com>**20090803131121
113 Ignore-this: ce862fb91c2b234211a8757f98690778
114]
115[Updates to follow the RTS tidyup
116Simon Marlow <marlowsd@gmail.com>**20090801220743
117 Ignore-this: 6e92412df93a66c12d75344053d5634
118 C functions like isDoubleNaN moved here (primFloat.c)
119]
120[Add integer-simple as a build option
121Ian Lynagh <igloo@earth.li>**20090722013151]
122[Use shift[LR]Integer in the Bits Integer instance
123Ian Lynagh <igloo@earth.li>**20090721222440]
124[depend directly on integer-gmp, rather than indirecting through integer
125Ian Lynagh <igloo@earth.li>**20090721185228]
126[Move the instances of Functor and Monad IO to GHC.Base, to avoid orphans
127Simon Marlow <marlowsd@gmail.com>**20090722102130
128 Ignore-this: a7d85ac0025d559674249de0108dbcf4
129]
130[move "instance Exception Dynamic" so it isn't an orphan
131Simon Marlow <marlowsd@gmail.com>**20090721093854
132 Ignore-this: 5ede91ecfec2112c91b699d4de87cd02
133]
134[Improve the index checking for array accesses; fixes #2120 #2669
135Ian Lynagh <igloo@earth.li>**20090719153228
136 As well as checking that offset we are reading is actually inside the
137 array, we now also check that it is "in range" as defined by the Ix
138 instance. This fixes confusing behaviour (#2120) and improves some error
139 messages (#2669).
140]
141[Make chr say what its argument was, if it's a bad argument
142Ian Lynagh <igloo@earth.li>**20090718151049]
143[remove unused warning
144Simon Marlow <marlowsd@gmail.com>**20090715124416
145 Ignore-this: 31f613654089d0f4a44363946087b41e
146]
147[warning fix: -fno-implicit-prelude -> -XNoImplicitPrelude
148Simon Marlow <marlowsd@gmail.com>**20090715122839
149 Ignore-this: dc8957249731d5bcb71c01899e5adf2b
150]
151[Add hGetEncoding :: Handle -> IO (Maybe TextEncoding)
152Simon Marlow <marlowsd@gmail.com>**20090715122519
153 Ignore-this: 14c3eff996db062da1199739781e4708
154 as suggested during the discussion on the libraries list
155]
156[Add more documentation to mkTextEncoding
157Simon Marlow <marlowsd@gmail.com>**20090715122414
158 Ignore-this: 97253b2624267df3a246a18121e8ea81
159 noting that "//IGNORE" and "//TRANSLIT" suffixes can be used with GNU
160 iconv.
161]
162[Add the utf8_bom codec
163Simon Marlow <marlowsd@gmail.com>**20090715122257
164 Ignore-this: 1c9396cd805201fe873a39382ced79c7
165 as suggested during the discussion on the libraries list.
166]
167[Export Unicode and newline functionality from System.IO; update Haddock docs
168Simon Marlow <marlowsd@gmail.com>**20090713113104
169 Ignore-this: c3f017a555335aa55d106253393f72e2
170]
171[add a comment about the non-workingness of CHARBUF_UTF16
172Simon Marlow <marlowsd@gmail.com>**20090707124406
173 Ignore-this: 98d00411b68d688b3b4cffc9507b1f35
174]
175[Fix build on Windows
176Ian Lynagh <igloo@earth.li>**20090711004351]
177[Fix some "warn-unused-do-bind" warnings where we want to ignore the value
178Ian Lynagh <igloo@earth.li>**20090710204513]
179[Use throwErrnoIfMinus1_ when calling getrusage
180Ian Lynagh <igloo@earth.li>**20090710204221]
181[Remove an unused import
182Ian Lynagh <igloo@earth.li>**20090710153345]
183[reportStackOverflow now returns IO ()
184Ian Lynagh <igloo@earth.li>**20090710153257
185 It used to do "return undefined" to return IO a.
186]
187[GHC.Conc.reportError now returns IO ()
188Ian Lynagh <igloo@earth.li>**20090710152646
189 It used to return IO a, by "return undefined".
190]
191[Fix some "warn-unused-do-bind" warnings where we want to ignore the value
192Ian Lynagh <igloo@earth.li>**20090710152526]
193[Minor SampleVar refactoring
194Ian Lynagh <igloo@earth.li>**20090710151438]
195[Fix "warn-unused-do-bind" warnings in GHC/IO/Handle/Text.hs
196Ian Lynagh <igloo@earth.li>**20090710122905]
197[Fix some "warn-unused-do-bind" warnings where we just want to ignore the result
198Ian Lynagh <igloo@earth.li>**20090710005638]
199[Use the result of writeCharBuf in GHC/IO/Encoding/Latin1.hs too
200Ian Lynagh <igloo@earth.li>**20090710004032]
201[Minor code tidyups in GHC.Conc
202Ian Lynagh <igloo@earth.li>**20090710003801]
203[Fix "warn-unused-do-bind" warning in GHC.Conc
204Ian Lynagh <igloo@earth.li>**20090710003530
205 If we fail to communicate with the IO manager then we print a warning
206 using debugErrLn from the ghc-prim package.
207]
208[Fix "warn-unused-do-bind" warnings in System.Posix.Internals
209Ian Lynagh <igloo@earth.li>**20090709164546]
210[Fix "warn-unused-do-bind" warnings where we really do want to ignore the result
211Ian Lynagh <igloo@earth.li>**20090709163912]
212[Add back imports needed on Windows
213Ian Lynagh <igloo@earth.li>**20090707181924]
214[Remove unused imports
215Ian Lynagh <igloo@earth.li>**20090707115810]
216[Remove unused imports from base
217simonpj@microsoft.com**20090706111842
218 Ignore-this: f9b5f353e3bb820f787c56d615b28765
219 
220 These unused imports are detected by the new unused-import code
221 
222]
223[Use the result of writeCharBuf
224Simon Marlow <marlowsd@gmail.com>**20090706133303
225 Ignore-this: 52288dd559bf4c4f313df6197091d935
226   
227 This only makes a difference when CHARBUF_UTF16 is in use, which it
228 normally isn't.  I suspect CHARBUF_UTF16 doesn't currently work for
229 other reasons (CHARBUF_UTF16 was an experiment before I wrote the
230 GHC.IO.Encoding.UTF* codecs), but this patch at least makes it
231 slightly closer to working.
232]
233[Remove some cruft from Data.HashTable
234Ian Lynagh <igloo@earth.li>**20090706181630]
235[Add 'eof' to Text.ParserCombinators.ReadP
236simonpj@microsoft.com**20090706111801
237 Ignore-this: 2aea7b848e00c894761bc4011adaa95d
238 
239 Add a ReadP parser that succeeds at the end of input. Very useful!
240 
241]
242[Don't export CLDouble for GHC; fixes trac #2793
243Ian Lynagh <igloo@earth.li>**20090705155120
244 We never really supported CLDouble (it was a plain old double underneath),
245 and pretending that we do does more harm than good.
246]
247[a byte between 0x80 and 0xBF is illegal immediately (#3341)
248Simon Marlow <marlowsd@gmail.com>**20090702081415
249 Ignore-this: dc19ef59a1a21118d5a7dd38aa2f611c
250]
251[avoid a warning
252Simon Marlow <marlowsd@gmail.com>**20090630084134
253 Ignore-this: c92a45ee216faf01327feae9fe06d6e2
254]
255[Add a wrapper for libiconv.
256Matthias Kilian <kili@outback.escape.de>**20090629183634
257 Ignore-this: 23c6047c0d71b745b495cc223574a47f
258]
259[#include <sys/times.h> if we have it (should fix build problems)
260Simon Marlow <marlowsd@gmail.com>**20090629085351
261 Ignore-this: a35e93b37ca9595c73460243180f4b9d
262]
263[set binary mode for existing FDs on Windows (fixes some GHCi test failures)
264Simon Marlow <marlowsd@gmail.com>**20090626120522
265 Ignore-this: 580cf636e9c77d8427aff6861d089481
266]
267[Move directory-related stuff to the unix package
268Simon Marlow <marlowsd@gmail.com>**20090625120325
269 Ignore-this: b997b3cbce0a46ca87ad825bbdc0a411
270 now that it isn't used on Windows any more.
271]
272[TAG 2009-06-25
273Ian Lynagh <igloo@earth.li>**20090625160056]
274Patch bundle hash:
2750eddd5471a0765babc52a8c452ed7a3948742049