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 (String, Int) ()
longestWord' [] = return ()
longestWord' (x:xs) = do x1@(word, idx) <- get
put (x, idx+1)
longestWord' xs
x2@(word', idx') <- get
if length word < length word' then put x2 else put x1
longestWord (x:xs) = execState (longestWord' xs) (x, 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