DEV Community

Cover image for My Way of (Purely Functional) Programming
#benaryorg
#benaryorg

Posted on

4

My Way of (Purely Functional) Programming

Image of Wix Studio

2025: Your year to build apps that sell

Dive into hands-on resources and actionable strategies designed to help you build and sell apps on the Wix App Market.

Get started

Top comments (4)

Collapse
 
justgage profile image
Gage

This is how I structure basically everything. Side effects on far edges, pure logic in the middle. It's only when I break from this pattern that I regret the code I write. I use Elixir for my web applications. The only thing I miss is the type system

Collapse
 
benaryorg profile image
#benaryorg

Apart from my previous reply to a similar question, I can point you to Yesod.

Collapse
 
gesuwall profile image
ガブリエル

What framework do you use for your "generic web applications"?

Collapse
 
benaryorg profile image
#benaryorg

The chapter "Application" (the one mentioning generic web applications) was meant as describing what services do from an outside perspective.
Internals may very well vary, but emphasizing on this structure removes a few problems (mostly state) and enables some performance optimizations (said laziness for external data).

To be honest, I did not yet write any meaningful application.
Mostly reinventing the wheel for educational purposes.

Haskell is just my hobby, as opposed to my job which is a GNU/Linux sysadmin.
The sysadmin background kind of taught me to just take already existing components and stick them together.
In sysadmin world this means sticking tools together with shell-scripts.
In Haskell world this means taking libraries like async or conduit and libraries for parsing the application specific protocols (HTTP, JSON) and sticking them together which, due to purely functional nature of those libraries is actually pretty easy.

I also mostly use Haskell itself for parsing (Parsec), so there is little I know in that respect.
However once again my sysadmin background helps out here: CLI-tools mostly take a stream of input on stdin and map it to something else on stdout.
If you write your "business logic" in a way that it takes a continuous stream of events and responds to each one using a response and a state-change then you can use it in any environment you like, as long as you can map something (HTTP requests, UDP packets, messages on unix-sockets, Websockets messages,.…) to that event stream.

Do not hesitate to ask for clarification, I'm pretty lousy in communicating my thoughts.

Sentry workshop image

Sick of your mobile apps crashing?

Let Simon Grimm show you how to fix them without the guesswork. Join the workshop and get to debugging.

Save your spot →

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay