Get the latest tech news

Functors, Applicatives, and Monads


Thanks to constructs like monads, imperative-style code can be reconciled with the purity and declarative nature of functional programming.

Instead of looping manually over each element and creating a new list, we can provide a transformation function to fmap and Haskell will handle the rest for us. Thanks to type inference and the function signature, Haskell knows that return applied on(x + 1) should put this value inside a Maybe Int. In Haskell, leveraging tools such as the do notation and the<- operator to bind variables, or return to wrap values inside monads allows developers to craft code that is not just concise but also remarkably powerful.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Monads

Monads

Photo of functors

functors

Photo of Applicatives

Applicatives

Related news:

News photo

Composable SQL

News photo

Functors to Monads: A Story of Shapes

News photo

Monads are like burritos (2009)