+data Conf = Conf { host :: String
+ , user :: String
+ , pass :: String
+ , dbnm :: String
+ }
+
+readConf :: String -> IO Conf
+readConf fn =
+ readFile fn >>= return . (foldr parseLine (Conf "" "" "" "")) . lines
+ where
+ parseLine :: String -> Conf -> Conf
+ parseLine l sum =
+ case words l of
+ [k, v] ->
+ case k of
+ "host" -> sum { host = v }
+ "user" -> sum { user = v }
+ "password" -> sum { pass = v }
+ "database" -> sum { dbnm = v }
+ _ -> error $ "bad key in config line \"" ++ l ++ "\""
+ _ -> error $ "bad config line \"" ++ l ++ "\""