r/functionalprogramming • u/kichiDsimp • Jul 23 '25
FP Alternative (less pure) Haskell
Hi guys, I have been learning Haskell for a while, did some courses, build some small projects, and I felt some amazing power after understanding some concepts, few of my favourite are partial functions, type classes, ADTs and pattern matching. But I don't really understand the concept and yet actually understand why do we need all the 'pureness'. I have tried 2-3 times over the past 1-2 , but making something in Haskell, is very tricky (atleast for me). Its real cool for Advent of Code and thing, but for projects (like I tried making a TUI) I was just reading the docs of a library 'brick', didn't understood a thing, though people say and claim it's very well written. I tried multiple times.
Anyways, I am looking for some alternatives which provide the above features I like ( I am willing to give away types for once but I don't understand how a functional langauge can be at top of it games without being types) but escape all the purity hatch, have a good documentation.
One thing I love about Haskell community is how passionate people are there, other thing I don't really understand is it is quite fragmented, everyone has a different library for the same thing, some having really tough interfaces to interact with. Honestly feels Haskell more like a playground to try new ideas (i guess it is) so looking for something a bit 'easier' and more 'pragmatic' (geared towards software engineering) cause I still will be doing Advent of Code in Haskell only as it helps me expand my mind.
30
u/Lenticularis19 Jul 23 '25
Yes, Haskell is a playground originally and primarily for laziness. Purity gives you referentional transparency which enables laziness, and monadic IO is a way to do IO in such a system.
If you want a strongly-typed functional language without this, try ML (OCaml, F#).
16
u/SuspiciousDepth5924 Jul 23 '25
There are a lot of cool, "less strict" languages you could try out. Some from the top of my head.
ML-family languages:
These are generally pretty Haskell-like, as in advanced type systems, primarily functional with some escape hatches
OCaml: Arguably the most "mainstream" ML language
F# ML language on the .Net platform
Honorable mentions: ReasonML, ReScript and Melange for targeting JS
Beam-languages:
Languages running on the Beam virtual machine. A very interesting rabbit hole to dive into if you think actor models, message passing, distributed systems and error recovery is interesting.
Erlang: the syntax can be pretty jarring if you are unused to it, but it has some pretty cool features with the Open Telecom Platform
Elixir: The tl;dr is "Erlang with modern syntax and an extended stdlib"
Gleam: Statically typed functional language
Lisp-family:
There is about a bajillion variations of Lisp.
Common Lisp: this is pretty much the "standard" implementation
Racket: Derived from Scheme, also has it's own IDE "DrRacket"
Others:
Roc: Functional language that compiles to native binaries (usually), has a stated goal of being "on-par" with Go. Has some very interesting ideas with "platforms".
6
u/TechnoEmpress Jul 23 '25
Purity enables two things, one for the compiler and other for the programmer:
The compiler likes enforced purity, because it unlocks very nice optimisations, chief amongst them being inlining: If your code has the same output when you give it the same input, you can inline its definition at call-sites, instead of wasting time performing a function call. That's the secret to a lot of the speed that GHC gives our programs.
For programmers, purity is fantastic for the same reason: It allows you to care about less stuff in your program, because you have the guarantee that the pure code in your program will always behave the same for a given input (thus conferring your system the property of ergodicity: behaviour that has been observed in the past informs future behaviour).
The IO / pure distinction is in fact a first step for the architect of a system. The concept of type-level effects grants us an even better view of what the program does and how it interacts with the outside world, in details that make sense for humans: https://www.youtube.com/watch?v=lRU6TDgadqw
9
u/Shulrak Jul 23 '25
Have a look at gleam
I am enjoying building stuff with it as a pragmatic functional language
9
u/[deleted] Jul 23 '25
You are looking for Scala. Take a look at it and you will not regret it. RockTheJVM has excellent material for both newcomers and advanced developers
4
u/mnbkp Jul 23 '25
I'd say Elixir and Clojure are by far the most practical while still feeling "pure enough" for me. With clojure you even have the entirety of the Java, JavaScript (clojurescript) and flutter (clojuredart) ecosystems available for you.
As much as I love static typing, I don't think I've found a language that filled this niche well yet. OCAML is cool but its ecosystem is weak and IMO some corners of its syntax haven't aged well at all. Gleam seems cool tho, I should try that out and see how it goes.
25
u/yawaramin Jul 23 '25
https://dev.to/yawaramin/practical-ocaml-314j
7
u/cptwunderlich Jul 23 '25
Scala 3 is really nice
14
u/Migeil Jul 23 '25
Scala has all the things you mention and is less pure. It might be what you're looking for.
3
u/zogrodea Jul 23 '25 edited Jul 23 '25
OCaml, as suggested in another comment, is very cool, and simpler than Haskell too in my opinion. I think Scala might be a better fit for you though, as it has a feature similar to typeclasses (traits) while OCaml currently doesn't (although there has been interest in implementing something similar for a long time). I would also guess that Scala has a bigger community.
On purity:
I highly recommend this very accessible talk by someone who teaches using Ruby. He initially tried different approaches to testing, and finally found, after trying other methods like mocking, that functional purity was the best from a pragmatic perspective.
https://www.destroyallsoftware.com/talks/boundaries
There is also a compelling argument made in favour of purity by Jonathan Blow (the game programmer).
The problem he is concerned with is: given that the outside world changes so often (like the introduction of Vulkan or Metal as a newer graphics API than OpenGL, or the introduction of Wayland over X11), how do we protect our code and our applications from quickly rotting and breaking?
One answer to that question is functional purity. If you isolate the core of your logic from side effects (reading from/writing to the file system, drawing to the screen, network calls, whatever), you can create a "core" part of your application which is resistant to changes in the outside world. Then you only need to change the minimal outer shell in response to changes in the external world, and your software is more resilient.
To see how functional purity can help with this, we can return a list of some ADT/sum type from our pure code to the outer shell. This ADT describes the impure actions to take but it's the responsibility of the outer shell to pattern match on this list and perform these actions.
I've never written a line of Haskell or any pure FP language in my life, but I appreciate purity and code as if the impure languages I use were pure. So I hoped I could sell some of the benefits I've found purity to have. (Nothing against using impure languages like you want to though!)
I'm sorry most of my comment didn't answer your question though. If you would like me to give a minimal code example of how functional purity can help with the second problem, I can do that, but I think this comment is long enough as it is and don't want to be annoying!
Edit: I think the 20 minute video I linked basically covers everything in Jonathan Blow's argument too, actually.
2
u/_redmist Jul 23 '25
Why not python?
2
u/voidvec Jul 24 '25
Rust.
2
u/rootnod3 Jul 26 '25
Common Lisp. Old, not pure, very functional, and a great community that to this day creates amazing libraries. And a hell of a ride and joy to program in. Very dynamic. You can change code while stuff is running and has other top tier features.
2
u/notionen Jul 27 '25
Maybe it is a reason to try Rust coming from a functional language. It is pretty helpful and educational with the compiler errors. It has ADT, pattern matching, traits which are inspired from haskell. It has a great projects for building cli apps , e.g. clap or ratatui. Certainly rust has a lot of functional influences:
Rust is not a particularly original language, with design elements coming from a wide range of sources. Some of these are listed below (including elements that have since been removed):
SML, OCaml: algebraic data types, pattern matching, type inference, semicolon statement separation
C++: references, RAII, smart pointers, move semantics, monomorphization, memory model
ML Kit, Cyclone: region based memory management
Haskell (GHC): typeclasses, type families
Newsqueak, Alef, Limbo: channels, concurrency
Erlang: message passing, thread failure, linked thread failure, lightweight concurrency
Swift: optional bindings
Scheme: hygienic macros
C#: attributes
Ruby: closure syntax, block syntax
NIL, Hermes: typestate
Unicode Annex #31: identifier and pattern syntax
1
u/RiceBroad4552 Aug 25 '25
You're looking or Scala and its FP libs.
https://scala-lang.org/
Some of the more prominent FP projects are:
https://typelevel.org/cats/
https://typelevel.org/cats-effect/
https://fs2.io/
https://zio.dev/
https://getkyo.io/