Am Sonntag 20 Dezember 2009 15:34:11 schrieb Volkan YAZICI:
OTH, I'm looking at my "translate" and it fails on infinite strings. Is it because of something lacking in my implementation, or a limitation of Regex.PCRE?
Regards.
I don't know whether the regex library can deal well with infinite input, but in translate input = do (head, word, tail) <- matchRegex input tailTrans <- (translate tail) return $ head ++ (transWord word) ++ tailTrans the IO-semantics require that the whole input is processed before anything is returned (translating tail might throw an exception, after all). Maybe it'll work with a little unsafeInterleaveIO magic: import System.IO.Unsafe translate input = do (head, word, tail) <- matchRegex input tailTrans <- unsafeInterleaveIO (translate tail) return $ head ++ (transWord word) ++ tailTrans