[Haskell-cafe] Re: Why is there no splitBy in the list module?
Jon Fairbairn
jon.fairbairn at cl.cam.ac.uk
Fri Jul 21 05:46:25 EDT 2006
On 2006-07-20 at 18:31BST I wrote:
> On 2006-07-13 at 10:16BST I wrote:
> > Hooray! I've been waiting to ask "Why aren't we asking what
> > laws hold for these operations?"
>
> Having thought about this for a bit, I've come up with the
> below. This is intended to give the general idea -- it's not
> polished code,
And already some changes (but all to comments) I'd
appreciate comments on the law below.
--- lib/split.lhs 2006/07/21 08:54:28 1.1
+++ lib/split.lhs 2006/07/21 09:42:49
@@ -17,10 +17,17 @@
=> "A Random List Of Words\nOn Lines"
+ I think the relevant law is
+ (forall x. all (not . p) (map f x)) =>
+ segmentsSatisfying (not . p) . fromParts . mapRight f . parts p
+ == segmentsSatisfying (not . p)
+
+ In other words, if f doesn't add any "not . p" elements,
+ the segments satisfying "not . p" are unchanged.
> contiguousParts p l = [a | Right a <- parts p l]
- so words = contiguousParts Char.isAlphaNum
+ so words = contiguousParts (not . Char.isSpace)
> segmentsSatisfying predicate
> = concat . map dropSeps . parts predicate
--
Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk
More information about the Libraries
mailing list