Hello all,
After learning some Haskell for class I realized that the functional programming paradigm isn't completely at odds with Nim. Nim supports pure functions (so long as you don't use mutable arguments) and has a type-based effect tagging system, so it's fairly easy to track side effects and achieve referential transparency. The remaining part is to structure code in a functional style by replacing iteration with recursion, deep branching with pattern matching, and exceptions/sentinel values with algebraic data types (except for exceptions thrown by IO and state mutators, perhaps).
So, I know that Nimble has several modules for functional programming. I've seen zero_functional, nimfp, and some functional features in nimboost.
My main question is if anyone has tried using these modules (or their own) in their projects, and what experiences they had doing so. Most of the Nim projects I see on GitHub are imperative. Has anyone made any projects using a primarily (although technically impure) functional style? Do you have any suggestions for me if I were to take that on myself?
Also, I am in the process of writing a Craft server in Nim (it uses async, and I was contemplating doing a redesign using a functional style. I'm afraid the application is too stateful to benefit from the functional style. I also know that many functional programmers feel that state handling is natural ("Haskell is the best imperative language around" seems to be a common rebuke of the idea that functional languages can't replace imperative ones).
TL;DR:
Cheers, twetzel59
I'm in a very similar situation to yours. Although we were unfortunately only taught F# in class ;)
I'm trying to appropriate a more functional style in nim. For the past couple of days I've been playing with zero_functional, but it does't seem to be very stable.
While I did manage to solve an advent of code challenge in a pure functional style using zero_functional, it gives me error in places i really wouldn't expect them.
For instance, this stupid simple snippet doesn't compile at all, and doesn't give an error when it fails either:
@[1,2,3] --> filter(it == 2)
This one won't compile either:
@[1,2,3] --> map(it * 2)
However, this one works just fine:
@[1,2,3] --> map((0, it * 2))
I did manage to write a functioning program using it, but it seems to be incredibly hit-or-miss with what will operations will work with it.
The project seems really cool though. I hope it matures.