Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
import Text.Regex
import Control.Monad.State
longestWord' :: [String] -> State Int String
longestWord' [x] = return x
longestWord' (x:xs) = longestWord' xs >>= \x' ->
if length x < length x'
then inc >> return x'
else return x
inc = modify (+1)
longestWord xs = runState (longestWord' xs) 0
main = print $ longestWord $ splitRegex (mkRegex " ") "The quick brown fox"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment