Skip to content

Instantly share code, notes, and snippets.

@kpgalligan
Forked from jrm2k6/gist:6584648
Last active December 23, 2015 05:09
Show Gist options
  • Save kpgalligan/6584675 to your computer and use it in GitHub Desktop.
Save kpgalligan/6584675 to your computer and use it in GitHub Desktop.
import System.Environment (getArgs)
stringToArray :: String -> [String]
stringToArray s = words s
findLongestWord :: String -> [String] -> String
findLongestWord x [] = x
findLongestWord l (w1:s1)
| length w1 > length l = findLongestWord w1 s1
| otherwise = findLongestWord l s1
main = do
args <- getArgs
content <- readFile (args !! 0)
let linesOfFile = lines content
putStr (unlines $ (map (findLongestWord "" ) (map words linesOfFile)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment