Mercurial > 12ws.info2
view exercises/src/Join.hs @ 39:9a7b9e0c9eb0 default tip
week 15 tutorial
author | Markus Kaiser <markus.kaiser@in.tum.de> |
---|---|
date | Fri, 08 Feb 2013 00:06:20 +0100 |
parents | f9386825bf71 |
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"