• + 1 comment

    I don't know your code, so I can't help you with that, but there are some hints I can give you:

    1. Use recursion instead of IORefs/ST + Vector as Haskell is optimised for recursion and but not for IORefs.

    2. Make sure, that nothing is loaded into memory completely. If you "consume" your strings instantly, the data will be streamed lazily from the console into your function which means less GC work.

    3. Don't worry, I have these problems too sometimes!

    Example:

    kmp :: String -> String -> Bool
    kmp [] _ = False
    kmp str search = if search `isPrefixOf` str then True else kmp (tail str) search
    

    Although being not the right algorithm, it fails only one test case.