[Haskell-cafe] Re: Substring replacements (was: Differences inoptimisiation

Branimir Maksimovic bmaxa at hotmail.com
Sun Dec 11 17:13:17 EST 2005




>From: Daniel Fischer <daniel.is.fischer at web.de>
>To: "Branimir Maksimovic" <bmaxa at hotmail.com>
>CC: Haskell-Cafe at haskell.org
>Subject: Re: Substring replacements (was: Differences inoptimisiation
>Date: Sun, 11 Dec 2005 18:12:12 +0100
>
>Unfortunately:
>Prelude SearchRep> searchReplace "aabaabba" "iii" "aabaabaabbaa"
>"aabaabaabb"

I've solved this case

>Prelude SearchRep> searchReplace "abaaba" "-" "abaaabaaba"
>"abaaabaab"
>

This one is cleaned up, but searching have to be adjusted for false
positive patterns.
So I need some more time, as this isn't quick fix.

>Seemingly, your algorithm assumes that the last component of the
>result of search'' is the beginning of the searched for pattern reversed --
>which needn't be.

Yes. That is the problem. Now I have to compare if it fits with searched
string.

>One comment on style (I like it in general):
>IMHO, the use of nested pairs and combinations of fst, snd is not very
>readable, using triples/quadruples and providing your own 
>accessor-functions
>(e.g. fst3, thd4) would improve that -- it might have an impact on
>performance, though, that would require a test or an answer from somebody
>more knowledgeable. And -- I'm not sure whether that is indeed so -- if you
>have an argument pattern (x:xs) which may be directly returned, as in
>
>fun (x:xs) | even x     = ([x],xs)
>                | otherwise = ([],x:xs)
>
>the list would have to be reconstructed from its head and tail, which could 
>be
>avoided by using an as-pattern
>
>fun xxs@(x:xs)
>     | even x      = ([x],xs)
>     | otherwise  = ([],xxs),
>however, that wouldn't be significant unless it happens really often and 
>the
>compiler might optimise it away anyway.

Thank you! This really helps . I 'll clean up my mess a bit.

Greetings, Bane.

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/



More information about the Haskell-Cafe mailing list