News for hackers. Stuff that matters.
Re:Why Haskell? by setopt on Thursday September 12, 2024 @07:01AM (#41519436)
> Haskell has had a profound impact on the way I think about programming and how I architect my code and build services.

> And I've had a lot of fun micro-optimizing Haskell code for Project Euler problems when I was studying.

Sounds a lot like my experience. I never really used Haskell for "real work", where I need support for high-performance numerical calculations that is simply better in other languages (Python, Julia, C/C++, Fortran).

But learning functional programming through Haskell – mostly by following the "Learn you a Haskell" book and then spending time working through Project Euler exercises using it – had a quite formative effect on how I write code.

I even ended up baking some functional programming concepts into my Fortran code later. For instance, I implemented the ability to "map" functions on my data structures, and made heavy use of "pure functions" which are supported by the modern Fortran standard (the compiler then checks for side effects).

It's however hard to go all the way on functional programming in HPC contexts, although I wish there were better libraries available to enable this.

Re:Why Haskell? by nextos on Thursday September 12, 2024 @09:01AM (#41520409)
> But learning functional programming through Haskell [...] had a quite formative effect on how I write code.

I think it is a shame Haskell has gained a reputation of being hard, because it can be an enriching learning experience. Lots of its complexity is accidental, and comes from the myriad of language extensions that have been created for research purposes.

There was an initiative to define a simpler subset of the language, which IMHO would have been great, but it didn't take off: https://www.simplehaskell.org. Ultimately, one can stick to Haskell 98 or Haskell 2010 plus some newer cherry-picked extensions.

Re:Why Haskell? by bbkane on Thursday September 12, 2024 @09:43AM (#41520873)
I think Elm is a fantastic "simplified Haskell" with pretty good beginner-friendly guides. It's unfortunate that Elm is mostly tied to the frontend and has been effectively abandoned for the last couple of years.

Interestingly, Elm has inspired a host of "successors", including Gleam + Lustre, which look really great (I haven't had a chance to really try them yet).

Re:Why Haskell? by earth_walker on Thursday September 12, 2024 @11:40AM (#41522131)
Elm's strengths are its constraints, which allow for simple, readable code that's easy to test and reason about - partly because libraries are also guaranteed to work within those constraints.

I've tried and failed several times to write Haskell in an Elm style, even though the syntax is so similar. It's probably me (it's definitely me!), but I've found that as soon as you depend on a library or two outside of prelude their complexities bleed into your project and eventually force you into peppering that readable, simple code with lifts, lenses, transformations and hidden magic.

Not to mention the error messages and compile times make developing in Haskell a chore in comparison.

p.s. Elm has not been abandoned, it's very active and getting better every day. You just can't measure by updates to the (stable, but with a few old bugs) core. For a small, unpopular language there is so much work going into high quality libraries and development tools. Check out

https://elmcraft.org/lore/elm-core-development

for a discussion.

Elm is so nice to work in. Great error messages, and near instant compile times, and a great ecosystem of static analysis, scaffolding, scripting, and hot reloading tools make the live development cycle super nice - it actually feels like what the lispers always promised would happen if we embraced repl-driven development.

Re:Why Haskell? by bbkane on Thursday September 12, 2024 @12:12PM (#41522449)
Thanks for the Elmcraft FAQ link. It's a great succinct explanation from the Elm leadership perspective (though tellingly not from the Elm leadership).

I feel like I understand that perspective, but I also don't think I'm wrong in claiming Elm has been effectively abandoned in a world where an FAQ like that needs to be written.

I'm not going to try to convince you though, enjoy Elm!!

Re:Why Haskell? by nextos on Thursday September 12, 2024 @09:51AM (#41520982)
What about Roc or Koka? Or simply moving to OCaml? It's looking pretty great after v5, with multicore and effect handlers.
Re:Why Haskell? by giraffe_lady on Thursday September 12, 2024 @10:33AM (#41521477)
OCaml is great but the type system is actually quite different from Haskell's once you get into it. It also has many "escape hatches" out of the functional pathway. Even if you approach it with a learner's discipline you'll run into them even in the standard lib.

With haskell you can look to the ecosystem to see how to accomplish specific things with a pure functional approach. When you look at ocaml projects in that way you often find people choosing not to.

Re:Why Haskell? by mattpallissard on Thursday September 12, 2024 @11:03AM (#41521767)
Oh but the OCaml module system is the bees knees.
Re:Why Haskell? by giraffe_lady on Thursday September 12, 2024 @11:05AM (#41521794)
Yeah I didn't mean any of this as a negative lol. I haven't touched haskell since I learned ocaml. I still think haskell has the edge as an educational language for functional programming and type systems though, which is kind of what we're talking about but not entirely.
Re:Why Haskell? by mattpallissard on Thursday September 12, 2024 @12:14PM (#41522472)
No worries, I was just adding my two cents.
Re:Why Haskell? by britzkopf on Thursday September 12, 2024 @12:50PM (#41522860)
I've often wondered if it having a reputation as being hard is accurate. Not necessarily because of syntax etc. but because of you don't already have a grounding in programming/engineering/comp sci. it can be difficult to fit the insights Haskell provides into any meaningful framework. That was my experience anyway, came to it too early and didn't understand the significance.
Re:Why Haskell? by gtirloni on Thursday September 12, 2024 @09:10AM (#41520512)
Sounds a lot like the C++ experience.

In my time learning Haskell a decade ago, it was rare to find some code that wasn't using an experimental extension.

Re:Why Haskell? by l5870uoo9y on Thursday September 12, 2024 @09:56AM (#41521034)
Pure functions are a crazy useful abstractions. Complex business logic? Extract it into a type-safe pure function. Still to "unsafe"? Testing pure functions are fast and simple. Unclear what a complex function does? Extract it into meaningful pure functions.
Re:Why Haskell? by ayakang31415 on Thursday September 12, 2024 @09:43PM (#41527350)
Haskell sounds like a good language to hone your programming skills. What kind of projects is Haskell suited for to get started (besides Euler project)? I use Python primarily for scientific research (mostly numerical computation).
Re:Why Haskell? by setopt on Saturday September 14, 2024 @11:03AM (#41540245)
I didn’t play with this myself, but I’ve heard good things about writing parsers in Haskell (e.g. the Parsec library and friends). Hell, even Pandoc is written in Haskell and that’s arguably the king of document parsers. So that could be one area. I also heard cool things about QuickCheck, which I think is the inspiration for Hypothesis in the Python ecosystem, if you want to explore more how to do testing. Perhaps the “Real World Haskell” book might be a good fit to see other possible projects.

Except the obvious functional programming concepts, one thing I enjoyed exploring in Haskell was “infinite data structures” and “lazy evaluation” – like how you could provide a recursion relation to define an infinite list of numbers, but only the finite elements in the list you ask to print are actually calculated behind the scenes. This “lazy evaluation” can be used to build algorithms that would be completely unreasonable in any other language.

I also liked how easy it is to define new data structures. Like implementing a minimal tree data structure can be done in literally one line of code, which is just ridiculous compared to most languages that I’ve tried.