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

> a real example of what problems monads solve

Have you ever used an async promise library in Javascript? Its a monad! (you have a function to create a new "async promise" given a sync value and you have a method to chain a promise with a callback that returns a new promise)

The complicated thing about monads is that they are an abstract interface. Having the abstract interface is good if you want to write generic code that works on all monads (and if you want to prove things about your code) but makes it hard to understand stuff. Another problem with monads is that its API can't be implemented directly in most languages so they get restricted to the more functional languages: one of the methods (>>=) receives an anonymous function as an argument (and many languages don't support those)and another method (the awkwardly named "return") is polymorfhic on its return value (OO languages can only handle polymorphism on the first input argument, the "this").



With templates/generics, polymorphic in return type is no problem. Consider Java Guava's

    Lists.<String>newArrayList()


Sure, but its kind of hackish and many people don't know about it. It also doesn't really apply to dynamic languages like Python :(




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

Search: