Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created February 12, 2011 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jutememo/823796 to your computer and use it in GitHub Desktop.
Save jutememo/823796 to your computer and use it in GitHub Desktop.
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