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 Haskell, one might need a new monad transformer layer or convert non-monadic code to monadic; in Rust one might have to rethink ownership patterns or add Rc to many places.) 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 combines especially well with laziness: for example one can find the length of a list even though evaluating the element of the list would result in runtime exceptions. 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 without compiler errors actually pass their tests.
(Yeah, I'm the guy with the co-worker who kept turning off -Wall in C++ because "nobody has time for that".)
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.
for x in range(10):
print(x)
forM_ [0..10] $ \x -> putStrLn xBut 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.)
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.)
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.
https://www.stackage.org/haddock/lts-22.22/base-4.18.2.1/Pre...
https://www.stackage.org/haddock/lts-22.22/base-4.18.2.1/Pre...
Why do you expect to understand the syntax of a language you never studied?
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.
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.)
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.
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.
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.
> Emacs/Lisp forever
I think of Haskell as the declarative statically typed lisp I’ve always wanted.