Skip to content

Instantly share code, notes, and snippets.

@waratuman
Created November 14, 2011 18:44
Show Gist options
  • Save waratuman/1364719 to your computer and use it in GitHub Desktop.
Save waratuman/1364719 to your computer and use it in GitHub Desktop.
λ ghc red.hs
[1 of 1] Compiling Main ( red.hs, red.o )
red.hs:8:5:
Couldn't match expected type `Char' with actual type `[Char]'
In the pattern: "merge"
In a case alternative: "merge" -> merge args putStrLn "done"
In the expression:
case action of {
"merge" -> merge args putStrLn "done"
otherwise -> putStrLn "unkown command" }
red.hs:15:23:
Couldn't match expected type `IO ()'
with actual type `Data.Map.Map k0 a0'
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)'
red.hs:19:11:
Couldn't match expected type `[t0]' with actual type `IO String'
In the return type of a call of `readFile'
In a stmt of a 'do' expression: text <- readFile path
In the expression:
do { text <- readFile path;
foldr (\ line acc -> (processLine line) : acc) [] (lines text) }
red.hs:25:13:
Couldn't match expected type `Float' with actual type `[Char]'
In the expression: price
In the expression: (date, price)
In the expression:
let [date, price] = splitOn "," line in (date, price)
λ
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 =
foldr (\file acc -> Data.Map.insert file (processFile file) acc) Data.Map.empty (init files)
processFile :: String -> [(String, Float)]
processFile path = do
text <- readFile path
foldr (\line acc -> (processLine line) : acc) [] (lines text)
processLine :: String -> (String, Float)
processLine line =
let [date, price] = splitOn "," line
in (date, price)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment