Create a gist now

Instantly share code, notes, and snippets.

Embed
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) = do x' <- longestWord' xs
if length x < length x'
then do 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