SV: SV: Haskell-beginners problem with memory consuption
petter.egesund at kunnskapsforlaget.no
Thu Oct 2 10:25:09 EDT 2003
Thanks for the tip - I will give it a try.
Fra: Ketil Malde [mailto:ketil+haskell at ii.uib.no]
Sendt: 2. oktober 2003 09:02
Til: Petter Egesund
Kopi: 'haskell-cafe at haskell.org'
Emne: Re: SV: Haskell-beginners problem with memory consuption
Petter Egesund <petter.egesund at kunnskapsforlaget.no> writes:
> fun :: String -> String
> look for pat1 in string - if found subst with sub1
> look for pat2 in string - if found subst with sub2
> look for pat3 in string - if found subst with sub3
> recurse until no pattern is found
I would structure this as
replace :: String -> [String] -> String
replace input patterns = ...
At each position of input, check for the presence of
patterns (use isPrefixOf) and conditionally replace it, else output
first char of input and recurse on input's tail.
This should make the function "online", so that it can be streamed
over a large but lazy list (say a file read with "readFile" -- hurry
up before Simon takes it away! :-) without explicitly constructing the
whole input or output String.
If I haven't seen further, it is by standing in the footprints of giants
More information about the Haskell-Cafe