3 ms·
"For instance, how can I open a file, split a line on a separator, then do something on the third column" Assuming we have doSomething :: Maybe String ->
by dllthomas 13y ago
"For instance, how can I open a file, split a line on a separator, then do something on the third column"
Assuming we have
doSomething :: Maybe String -> IO ()
which turns some optional string into an action to perform, you could say:
mapM_ (doSomething . listToMaybe . drop 2 . words) . lines =<< readFile filename
The IO action readFile produces a (lazy) String, lines chops it into a (lazy) list of Strings - on each of those we break it into columns, get rid of two of them, get Just the head if it exists (otherwise, Nothing), turn those into the actions we want with doSomething, and sequences those actions. The result is a new action.
"Also, how can I talk to MySql or Sqlite?"
http://www.yesodweb.com/book/persistent http://www.yesodweb.com/book/persistent