Last active
August 29, 2015 13:56
-
-
Save markhibberd/8831869 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
the contents of a |
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
runhaskell io.hs files.txt | |
============ a.txt | |
the contents of a | |
============ b.txt | |
the contents of b | |
============ c.txt | |
the contents of c |
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
the contents of b |
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
the contents of c |
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
a.txt | |
b.txt | |
c.txt |
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 System.Environment | |
import Control.Applicative | |
import Control.Monad | |
{- | |
Functions -- | |
getArgs :: IO [String] | |
putStrLn :: IO String | |
readFile :: String -> String | |
lines :: String -> [String] | |
void :: IO a -> IO () | |
Abstractions -- | |
Applicative, Monad: | |
<$>, <*>, >>=, =<<, pure | |
Note, standard library lists -- | |
Cons (`:.`) is just `:` | |
Nil is `[]` | |
Problem -- | |
Given a single argument of a file name, read that file, | |
each line of that file contains the name of another file, | |
read the referenced file and print out its name and contents. | |
Example -- | |
Given file files.txt, containing: | |
a.txt | |
b.txt | |
c.txt | |
And a.txt, containing: | |
the contents of a | |
And b.txt, containing: | |
the contents of b | |
And c.txt, containing: | |
the contents of c | |
$ runhaskell io.hs "files.txt" | |
============ a.txt | |
the contents of a | |
============ b.txt | |
the contents of b | |
============ c.txt | |
the contents of c | |
-} | |
-- getArgs :: IO [String] | |
-- Hint: use getArgs and run | |
main :: IO () | |
main = undefined | |
-- | |
-- Hint: use getFiles and printFiles | |
run :: String -> IO () | |
run = undefined | |
getFiles :: [String] -> IO [(FilePath, String)] | |
getFiles = undefined | |
getFile :: FilePath -> IO (FilePath, String) | |
getFile = undefined | |
printFiles :: [(FilePath, String)] -> IO () | |
printFiles = undefined | |
printFile :: FilePath -> String -> IO () | |
printFile = undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment