Created
February 13, 2011 01:42
-
-
Save jutememo/824329 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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