Skip to content

Instantly share code, notes, and snippets.

@waratuman
Created November 16, 2011 17:00
Show Gist options
  • Save waratuman/1370645 to your computer and use it in GitHub Desktop.
Save waratuman/1370645 to your computer and use it in GitHub Desktop.
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)'
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