Mercurial > 12ws.info2
view exercises/src/Join.hs @ 23:f9386825bf71
week 10
author | Markus Kaiser <markus.kaiser@in.tum.de> |
---|---|
date | Wed, 19 Dec 2012 23:22:42 +0100 |
parents | |
children |
line wrap: on
line source
module Join where import Control.Monad import Data.List import System.Environment (getArgs) {-- nicht veraendern --} data Field = A Int | B Int readInt :: String -> Maybe Int readInt s = case [x | (x,t) <- reads s, ("","") <- lex t] of [x] -> Just x _ -> Nothing {-- H10.2 --} doJoin :: [String] -> [String] -> [String] doJoin = undefined doJoinFormat :: [Field] -> [String] -> [String] -> [String] doJoinFormat = undefined parseFormat :: String -> Maybe [Field] parseFormat = undefined {-- Vorbereitetes GerĂ¼st --} readLines :: String -> IO [String] readLines path = liftM lines $ readFile path main :: IO () main = do args <- getArgs case args of ["-f", fmtStr, file1, file2] | Just fmt <- parseFormat fmtStr -> mapM_ putStrLn =<< liftM2 (doJoinFormat fmt) (readLines file1) (readLines file2) [file1, file2] -> mapM_ putStrLn =<< liftM2 doJoin (readLines file1) (readLines file2) _ -> putStrLn "Syntax: Join [-f format] file1 file2"