-
-
Save waratuman/1370645 to your computer and use it in GitHub Desktop.
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
red.hs:13:23: | |
Couldn't match expected type `IO a0' | |
with actual type `Data.Map.Map k0 a1' | |
In the return type of a call of `Data.Map.insert' | |
In the expression: Data.Map.insert file (processFile file) acc | |
In the first argument of `foldr', namely | |
`(\ file acc -> Data.Map.insert file (processFile file) acc)' |
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 | |
import Data.List.Split | |
import qualified Data.Map | |
main = do | |
(action:args) <- getArgs | |
case action of | |
"merge" -> merge args | |
otherwise -> putStrLn "unkown command" | |
merge :: [String] -> IO () | |
merge files = do | |
foldr (\file acc -> Data.Map.insert file (processFile file) acc) Data.Map.empty (init files) | |
return () | |
processFile :: String -> IO [(String, Float)] | |
processFile path = do | |
text <- readFile path | |
return (foldr (\line acc -> (processLine line) : acc) [] (lines text)) | |
processLine :: String -> (String, Float) | |
processLine line = | |
let [date, price] = splitOn "," line | |
in (date, (read price :: Float)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment