Created
February 6, 2011 12:06
-
-
Save kana/813326 to your computer and use it in GitHub Desktop.
Reviewing Haskell by writing Unix commands
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.Time | |
import System.Locale | |
main = getClockTime >>= | |
toCalendarTime >>= | |
putStrLn . formatCalendarTime defaultTimeLocale "%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
import System.Environment | |
main = getArgs >>= putStrLn . unwords |
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.Exit | |
main = exitFailure |
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.Directory | |
main = getCurrentDirectory >>= putStrLn |
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 Data.List | |
main = getContents >>= putStrLn . unlines . sort . lines |
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 | |
main = getArgs >>= \args -> ( | |
getContents >>= \s -> ( | |
tee args s | |
) | |
) | |
tee :: [String] -> String -> IO () | |
tee [] s = putStr s | |
tee (filename:rest) s = writeFile filename s >> tee rest s |
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.Exit | |
main = exitWith ExitSuccess |
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
main = getContents >>= \x -> putStrLn $ unlines $ uniq $ lines x | |
uniq :: (Eq a) => [a] -> [a] | |
uniq [] = [] | |
uniq (x:[]) = [x] | |
uniq (x:xs) = if x == head xs then uniq xs else x:(uniq xs) |
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 | |
main = getArgs >>= putStrLn . yes | |
yes :: [String] -> String | |
yes xs = unlines $ repeat $ unwords $ normalizeArguments xs | |
normalizeArguments :: [String] -> [String] | |
normalizeArguments [] = ["y"] | |
normalizeArguments xs = xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment