>>155 確かこんなのあったな〜・・・と、inword/outword関数の相互再帰で書いてみた。
Haskell
main = (putStrLn.f "abcdefrt") "acdgefgg"
f xs ys | g xs ys =[]
f (x:xs) (y:ys) | x == y = outword (x:xs) (y:ys)
f xs ys = inword xs ys
inword xs ys | g xs ys = ']':[]
inword (x:xs) (y:ys) | x == y = ']':x:outword xs ys
inword (x:xs) (_:ys) = x:inword xs ys
outword xs ys | g xs ys = []
outword (x:xs) (y:ys) | x == y = x:outword xs ys
outword (x:xs) (_:ys) = '[':x:inword xs ys
g xs ys = or [null xs, null ys]