goal2 s = newstring s
where
newstring [] = []
newstring (h : m : t)
| h == ' ' && m /= ' ' = m : newstring t
| h /= ' ' && m == ' ' = newstring t
| m == ' ' = newstring t
| otherwise = newstring t
Ok, one module loaded.
ghci> goal2 " apple pen pen pen" "appp"
ghci> goal2 " pen pineaple appen pen" "pp*** Exception: assign1_task1.hs:(103,5)-(108,42): Non-exhaustive patterns in function newstring
ghci> goal2 " pen pineapple apple pen" "ppap"