News for hackers. Stuff that matters.
Re:The Cult of the Haskell Programmer by julianeon on Monday May 13, 2024 @10:14PM (#40350980)
This would be a great place for any Haskell programmers to insert their own thoughts. I like the look of Haskell myself but I've spent more time with Rust because it seems more practical.
Re:The Cult of the Haskell Programmer by eru on Monday May 13, 2024 @10:25PM (#40351029)
If you like another language that's a bit like Haskell-but-more-practical, give OCaml a try. They even have a for-loop in OCaml!
Re:The Cult of the Haskell Programmer by habitue on Monday May 13, 2024 @11:18PM (#40351350)
There's... forM_ in Haskell. that's basically a for loop, right?
Re:The Cult of the Haskell Programmer by eru on Tuesday May 14, 2024 @01:17AM (#40351855)
Yes, you can implement your own loops in Haskell and OCaml (and Scheme and even the GCC-variant of C).

However, I meant specifically that OCaml is so 'pragmatic' that they have a for-loop as a built-in syntactic element in the language. They also have mutable variables built-in. In eg Haskell those are 'only' available as part of the standard library.

Re:The Cult of the Haskell Programmer by habitue on Tuesday May 14, 2024 @02:28AM (#40352222)
Sorry, bad attempt at humor. I knew what you meant, I was just poking fun at forM_ for being bizarre and unergonomic
Re:The Cult of the Haskell Programmer by tome on Tuesday May 14, 2024 @03:45AM (#40352626)
What do you find bizarre and unergonomic about it?
Re:The Cult of the Haskell Programmer by habitue on Tuesday May 14, 2024 @10:55AM (#40355850)
If you're quite used to Haskell, it's nbd. If you're coming from another language with for loops and someone tells you it's a for loop, you might be surprised that you need to use $ and the loop variable comes after the sequence

for x in range(10):

    print(x)
forM_ [0..10] $ \x ->

  putStrLn x
Re:The Cult of the Haskell Programmer by karmakurtisaani on Tuesday May 14, 2024 @12:45PM (#40357169)
I'm convinced the people who came up with Haskell syntax were on some sort of bath salts.
Re:The Cult of the Haskell Programmer by nequo on Tuesday May 14, 2024 @01:03PM (#40357356)
The reason it looks the way it does is that forM_ is just a function like any other, not a keyword in a dedicated syntactic construct.
Re:The Cult of the Haskell Programmer by karmakurtisaani on Tuesday May 14, 2024 @01:08PM (#40357407)
Yep, and then there's the $, \ and PutStrLn. As a non-Haskell programmer none of those mean anything to me.
Re:The Cult of the Haskell Programmer by nequo on Tuesday May 14, 2024 @01:28PM (#40357668)
$ is short for “put everything to the right inside parentheses” and \x -> y defines an anonymous function.

Why do you expect to understand the syntax of a language you never studied?

Re:The Cult of the Haskell Programmer by karmakurtisaani on Tuesday May 14, 2024 @01:47PM (#40357884)
> $ is short for “put everything to the right inside parentheses”

There's, you know, also the actual parentheses that everyone already knows.

> Why do you expect to understand the syntax of a language you never studied?

Because most languages have a syntax that you can grasp almost immediately, since they conform to a common syntax, rather than invent everything all over again. Then you can focus on the actual features of the language and are not bogged down by syntax.

Re:The Cult of the Haskell Programmer by tasuki on Tuesday May 14, 2024 @03:39PM (#40359264)
You know, perhaps Haskell isn't the right language for you. That's fine. Why should it conform to your syntactic preferences?
Re:The Cult of the Haskell Programmer by nequo on Tuesday May 14, 2024 @02:41PM (#40358591)
It doesn't take more than two minutes to understand what $ and \x -> y do, and if you start writing out those parentheses, you will also realize why $ is part of idiomatic Haskell.
Re:The Cult of the Haskell Programmer by eru on Tuesday May 14, 2024 @07:01PM (#40361129)
> There's, you know, also the actual parentheses that everyone already knows.

Those are also available, and are legal syntax in Haskell.

> Because most languages have a syntax that you can grasp almost immediately, since they conform to a common syntax, rather than invent everything all over again.

I hope you don't count C's `for(something, something; something; something) {` as part of that intuitive bunch?

Btw, Haskell didn't re-invent the wheel for most of its syntax: they stuck to the common and already established syntax of the ML family of languages. ML is from 1973. (For comparison, Wikipedia says C is from 1972.)

Re:The Cult of the Haskell Programmer by karmakurtisaani on Wednesday May 15, 2024 @03:20AM (#40364029)
> Those are also available, and are legal syntax in Haskell.

I don't especially like the idea of making multiple notations for the same thing, to be honest.

> I hope you don't count C's `for(something, something; something; something) {` as part of that intuitive bunch?

Not my favorite, but at least widely used. I find the style in for example Rust the most easy on the eye.

> Btw, Haskell didn't re-invent the wheel for most of its syntax

Yeah I actually suspected this was the case.

Re:The Cult of the Haskell Programmer by eru on Thursday May 16, 2024 @03:27AM (#40376008)
> I don't especially like the idea of making multiple notations for the same thing, to be honest.

I can appreciate that sentiment, but I'm afraid the designers of Haskell had a different approach there.

There often a few different ways to express something. But at least they can often be understood as thin syntactic sugaring of one into the other. It's not like C++ or Perl (or even Ruby with its different types of closures) where you have tons of overlapping ways to express something, and they are all subtly different.

> I find the style in for example Rust the most easy on the eye.

I'm not sure about easy-on-the-eye, but I find Rust mostly quite bearable, too.

Re:The Cult of the Haskell Programmer by tome on Thursday May 16, 2024 @05:06AM (#40376447)
> > I don't especially like the idea of making multiple notations for the same thing, to be honest. > > I can appreciate that sentiment, but I'm afraid the designers of Haskell had a different approach there.

It's also very difficult to achieve in practice. According to the Zen of Python "There should be one-- and preferably only one --obvious way to do it" but I don't think even Python lives up to that.

Re:The Cult of the Haskell Programmer by eru on Saturday May 18, 2024 @11:29PM (#40404024)
Yes, it's only aspirational in Python, too.
Re:The Cult of the Haskell Programmer by tome on Wednesday May 15, 2024 @03:34AM (#40364094)
I think what you're complaining about is not syntax, but lack of syntax. There's nothing syntactially special about this "for loop"! What's the benefit of this then? Firstly, less to learn. If you already understand $ and lambdas, then you understand this structure, and can reuse your knowledge in many places, for example

    withTempFile "foo" $ \tmpFile -> do
       <do something with tmpFile>

    flip fmap myList $ \e -> do
      <do something with each element i>
And you can even create your own constructs. You're not limited to the ones that are built in.

(The [0..10] is actually syntax, and I think that's quite unfortunate. `range 0 10` would have been just as good.)

Re:The Cult of the Haskell Programmer by eru on Thursday May 16, 2024 @03:25AM (#40376002)
> (The [0..10] is actually syntax, and I think that's quite unfortunate. `range 0 10` would have been just as good.)

Well, Haskell is in fact flexible enough that you can define that range function.

But one reason to make it syntax is that you can define things like [0..], which would be between awkward to impossible to do with a single `range` function in Haskell.

Re:The Cult of the Haskell Programmer by tome on Thursday May 16, 2024 @05:07AM (#40376453)
Re:The Cult of the Haskell Programmer by eru on Tuesday May 14, 2024 @06:58PM (#40361109)
You don't need the $ anymore with `BlockArguments`.

But overall, Haskell isn't really any worse here than Rust's for-each; or even C's weird for-loop (where you just have to rote learn what the three parts in the header of the loop do). I agree it's worse than Python's or Rust's vanilla for-loop.

I mostly like Python's syntax, I just wish they would make their would declare their indentation syntax to be sugar for a curly brace syntax (like Haskell does), and their would make their statements and blocks give values, like Haskell and Rust do.

(Of course, I have some other things I don't like in Python. But her syntax is by-and-large fine.)

Re:The Cult of the Haskell Programmer by kccqzy on Monday May 13, 2024 @11:06PM (#40351279)
Rust is indeed more practical than Haskell, I wouldn't deny that. But Rust lacks full support for higher-kinded types. Exploring a few type classes (known as traits in Rust) like Applicative, Foldable, Traversable can really open your mind. An exaggerated quip by Haskellers is that there are entire libraries on NPM that simply implement the single function `traverse`. While that's an exaggeration, it really helps to look at a few dozen things the single `traverse` function can do to realize its generality.
Re:The Cult of the Haskell Programmer by eru on Tuesday May 14, 2024 @01:21AM (#40351875)
Well, we have entire libraries in Haskell that implement `traverse` for a specific data type, too. The nice thing in Haskell is that the language is strong enough that we can tell the compiler that all those disparate implementations have something in common.
Re:The Cult of the Haskell Programmer by reduck on Monday May 13, 2024 @10:30PM (#40351056)
Your profile says

> Emacs/Lisp forever

I think of Haskell as the declarative statically typed lisp I’ve always wanted.

Re:The Cult of the Haskell Programmer by danieltanfh95 on Monday May 13, 2024 @10:53PM (#40351195)
then you've never really wanted a lisp...
Re:The Cult of the Haskell Programmer by reduck on Monday May 13, 2024 @11:31PM (#40351399)
Abounding pith is a poor substitute for knowledge.

There are plenty of typed lisps and lisp dialects: typed racket, hacket, carp.

Many lisps emphasise principles that make them all but a hairs width from being declarative: the original lisp was purely functional disallowing side effects, almost all lisps focus on higher order functions, and clojure forces immutability.

Re:The Cult of the Haskell Programmer by eru on Tuesday May 14, 2024 @01:22AM (#40351884)
Why not? If your comparison is eg C, Haskell and Lisp share a lot in common.
Re:The Cult of the Haskell Programmer by develop7 on Tuesday May 14, 2024 @04:01AM (#40352705)
Could you elaborate on the "more practical" bit?
Re:The Cult of the Haskell Programmer by julianeon on Tuesday May 14, 2024 @12:30PM (#40356974)
More jobs I could get with it, more open source tools or projects I could work on with it.
Re:The Cult of the Haskell Programmer by kccqzy on Tuesday May 14, 2024 @11:51AM (#40356529)
I just thought of one more thing. I really like -fdefer-type-errors in GHC and wish Rust has something similar.

Both Rust and Haskell are very opinionated in the way the program is organized. Adding a seemingly small feature can often result in larger-than-expected refactoring. In GHC, type errors can be deferred until run time, until the point where the expression containing the type error is forced. If the expression containing the type error is never evaluated, the program works; if it is, you get an exception raised. This is useful when I'm halfway through a large refactoring, when there are plenty of errors remaining, but I want to run my test suite to determine whether the parts that work actually pass their tests.

Re:The Cult of the Haskell Programmer by mcguire on Tuesday May 14, 2024 @02:31PM (#40358476)
As long as you remember to turn it off after you're finished refactoring. :-)

(Yeah, I'm the guy with the co-worker who kept turning off -Wall in C++ because "nobody has time for that".)