Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"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



Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: