[Haskell-beginners] multreplace
prad
prad at towardsfreedom.com
Fri Jul 2 00:57:20 EDT 2010
so after being inspired by the continual excellent help here, i am
trying my hand at writing a multiple replace using Useful.replace
Useful.replace origStr pattStr replStr
gives for Useful.replace "This original string" "orig" "very orig"
"This very original string"
what i want to do is something like
multRepl origStr [patt1,patt2] [repl1,repl2]
so we get from
multRepl "This original string" ["orig","ing"] ["very orig","ucture"]
"This very original structure"
what i have come up with is:
multRepl :: String -> [String] -> [String] -> [String]
multRepl str ss rs = [U.replace str a b | (a,b) <- (zip ss rs)]
this produces in 2 passes:
["This very original string","This very original structure"]
to get the final result, i could just
last multRepl
but i would like to know if this is a good way to do things.
i suppose going through the incremental steps is obligatory, but after
printing out the result and seeing these steps, it feels like i'm
producing throw away stuff - though perhaps that's just an illusion
stemming from a similar function php5 has where you get the result
without seeing anything behind the scenes.
--
In friendship,
prad
... with you on your journey
Towards Freedom
http://www.towardsfreedom.com (website)
Information, Inspiration, Imagination - truly a site for soaring I's
More information about the Beginners
mailing list