Created
April 12, 2015 03:17
-
-
Save quephird/5fe2620e6183d52a64f2 to your computer and use it in GitHub Desktop.
Using the supplied interactWith function, write another function that writes the first word of each line to another file.
This file contains hidden or 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
interactWith :: (String -> String) -> FilePath -> FilePath -> IO () | |
interactWith f inputFile outputFile = do | |
input <- readFile inputFile | |
writeFile outputFile (f input) | |
writeFirstWords inputFile outputFile = interactWith firstWords inputFile outputFile where | |
firstWord "" = "" | |
firstWord line = head $ words line | |
firstWords file = unlines $ map firstWord $ lines file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment