Mercurial > 12ws.info2
view exercises/src/Join.hs @ 30:8bf7ca2663d2
Advanced AdditionParser
author | Markus Kaiser <markus.kaiser@in.tum.de> |
---|---|
date | Sat, 12 Jan 2013 14:36:43 +0000 |
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"