Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pure FP in Scala?

I was under the impression that there are folks out there that do write pure applications using Scalaz, but based on this example: [ stacking StateT in scalaz ], it looks like anything real would also be impossibly hairy.

Are there any guidelines or examples of real, modular, loosely-coupled, pure applications in Scala? I'm expecting that this means scalaz.effect.SafeApp and RWST over IO, but I'd like to hear from folks who have done it.

Thanks.

Edit: In the absence of an answer, I've started collecting resources as an answer below. If you have any examples or related links to contribute, please do.

like image 453
arya Avatar asked Nov 01 '22 00:11

arya


2 Answers

i think you are mixing two different things. one is pure functional programming and second is scala type system. you can do 'pure' programming in any language, even in java. if the language is funvtional than you will have pure functional programming.

  • does it make your programs work faster? depends on the program - it scales better but for single threaded parts you will rather loose performance.
  • does it 'save your cognition'? it depends on how good you are in what you are doing. if you work with FP, monads, arrows etc on the daily basis then i assume it may help significantly. if you show the code to the OO developer he probably won't understand anything.
  • does it save the development time? as previously, i think it may but to be honest it doesn't matter that much. you more often read the code rather than write it
  • can you do useful stuff in PFP? yes, some companies makes money on haskell

and now, can it be done in scala? for sure. will anyone do it in scala? probably not because it's too easy to break the purity, because type system is too weak and because there are better, 'more pure' tools for it (but currently not on jvm)

like image 174
piotrek Avatar answered Nov 11 '22 22:11

piotrek


I guess I will start collecting resources here, and update as I find more.

  • Functional Reactive Programming: stefan hoeck's blog, github, examples
  • Monadic effect worlds for interacting safely with mutable data. (tpolecat)
  • Mellow database access for Scala (tpolecat)
  • Dependency Injection without the Gymnastics (tony, rúnar)

  • Google search for "extends SafeApp"

like image 39
arya Avatar answered Nov 12 '22 00:11

arya