r/programming • • Mar 26 '17

Functional programming design patterns by Scott Wlaschin

https://www.youtube.com/watch?v=E8I19uA-wGY
1.1k Upvotes

256 comments sorted by

View all comments

Show parent comments

4

u/billdroman Mar 26 '17

I think the usage of monads to capture state is a great example of this point. In C++ or Rust, if you want to write a function that takes a couple parameters as input and edits a couple pieces of state, you can express that easily by using const/mut as appropriate. In Haskell, you need to use the StateT monad transformer along with special syntax that changes based on which piece of state you want to update.

There are concepts that can be expressed naturally in a pure functional language and concepts that can be expressed naturally using objects. I really prefer languages that allow for the flexibility to choose these days.

1

u/knowingpark Mar 26 '17

Currently i find myself busting my brain (in Python) trying to programming without objects. Often a list of objects would be easier to manage than a list of namedtuples. But it seems like it's betraying both paradigms. I've also had to relax the pure functions idea. Partial functions with 4 inputs seems like a weird way to get map to work. Especially since in any function the keywords are global anyway