Last active
September 11, 2020 00:07
-
-
Save coproduto/3c73a8da7568e0b8398ad024d614938d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
data ReadState = None | Input | Output | |
split :: (Char -> Bool) -> String -> [String] | |
split f s = let (prefix, rest) = break s in | |
case rest of | |
[] -> [prefix] | |
[c] -> [prefix] | |
(c:cs) -> prefix : (split f cs) | |
main :: IO () | |
main = do | |
handle <- openFile "nome.do.arquivo" | |
contents <- hGetContents handle | |
processLines None (lines contents) | |
processLines :: [String] -> ReadState -> IO () | |
processLines [] _ = pure () | |
processLines (line:rest) state = | |
let [code, value] = split (== '|') line | |
newState = processLine state code value in | |
processLines rest newState | |
processLine :: ReadState -> String -> String -> ReadState | |
processLine _ "C100" status | |
| status == "entrada" = Input | |
| status == "saida" = Output | |
| otherwise = error "Linha inválida!" | |
processLine _ _ _ = ... -- tratar os outros casos |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment