Thanks for the tip - I will give it a try.

PE

-----Opprinnelig melding-----
Fra: Ketil Malde [mailto:[EMAIL PROTECTED]
Sendt: 2. oktober 2003 09:02
Til: Petter Egesund
Kopi: '[EMAIL PROTECTED]'
Emne: Re: SV: Haskell-beginners problem with memory consuption


Petter Egesund <[EMAIL PROTECTED]> 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.

-kzm
-- 
If I haven't seen further, it is by standing in the footprints of giants
_______________________________________________
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to