News for hackers. Stuff that matters.
Re: Haskell is our first choice for building production soft... by jcelerier on Monday January 11, 2021 @05:46AM (#25727169)
> Many programmers encounter statically typed languages like Java or C++ and find that the compiler feels like an annoyance. By contrast, Haskell’s static type system, in conjunction with compile-type time checking, acts as an invaluable pair-programming buddy that gives instantaneous feedback during development.

the reason they "find that the compiler feels like an annoyance" is because their first exposure to Java / C++ is in school where they have an assignment due for tonight and the compiler won't stop banging pages of errors about std::__1::basic_string<char, std::__1::allocator<char>> and what the fuck is that shit I just want to make games !!11!1!

In contrast Haskell is often self-taught which gives a very different set of incentives and motivations.

As a mostly C++ programmer making sure that I get compiler errors as often as possible by encoding most preconditions in the type system is one of the most important part of my job and make the language very easy to use when you use an IDE which allows to click on an error and going to the right place in the code.

Re: Haskell is our first choice for building production soft... by corty on Monday January 11, 2021 @06:27AM (#25727529)
Annoyance about C++ errors isn't only about the error occuring. With me, it is predominantly about the utter unusability of the error messages. C++ has postprocessors you can use to get your 20 page STL errors down to a few lines just by reversing the expansion the compiler did to show you mere mortal something that you might recognize as your code instead of template-cthulhu.

Haskell has such situations as well, but usually far less verbose. Getting something to typecheck because you wrote down something incompatible uninferable still sucks. But far less than C++.

Re: Haskell is our first choice for building production soft... by Rompect on Monday January 11, 2021 @07:19AM (#25727939)
In contrast, Rust's compiler sometimes gives suggestions for changes which can often just be copied.
Re: Haskell is our first choice for building production soft... by jhayward on Monday January 11, 2021 @09:09AM (#25729012)
I'm always puzzled by people who see this as somehow a good thing.

If the Rust compiler can figure out what the type should be, why doesn't it just do the cross-function inference, and leave the complicated nested implications which only obscure the intent and effect out of it?

If having the programmer specify types is an important check on the correctness of the code that is written, how is blindly copying, without understanding some 60+ character type specification string from an error message going to help demonstrate correctness? All it does is make two sections "consistent". It isn't something the programmer understands or specifies as a type check.

Re: Haskell is our first choice for building production soft... by steveklabnik on Monday January 11, 2021 @11:31AM (#25731255)
> why doesn't it just do the cross-function inference

It could! This is an explicit design choice. There are a few different reasons. They're all sort of connected...

In general, Rust takes the position that the type signature is the contract. If you inferred the types on function signatures, changing the body of your function could change the signature, which means that breaking changes are harder to detect. It also leads to "spooky action at a distance" errors; I could change a line of code in function A, but then the compiler complains about the body of some unrelated code in a totally different part of the codebase, because that changed the signature of function A, which changed the signature of function B, which is called in function C. My error shows C is wrong, but I made a mistake in the body of A. That's confusing. Much nicer to say "Hey you said the signature of A is X but the body is Y, something is wrong here."

I am gonna handwave this one slightly because I don't fully remember all of the details, but full program inference and subtyping is undecidable. Rust doesn't have subtyping in general for this and other reasons, but lifetimes do have subtyping. I am sure this would get ugly.

Speaking of getting ugly, Rust is already criticized often for compile times. Full program inference would make this much, much worse. Again with that changing signatures issue, cascading signature change would cause even more of your program to need to be recompiled, which means that bad error message is gonna take even longer to appear in the first place.

I think there might be more but those are the biggest ones off the top of my head.

Re: Haskell is our first choice for building production soft... by leshow on Monday January 11, 2021 @12:05PM (#25731873)
> I am gonna handwave this one slightly because I don't fully remember all of the details, but full program inference and subtyping is undecidable. Rust doesn't have subtyping in general for this and other reasons, but lifetimes do have subtyping. I am sure this would get ugly.

Correct. Haskell is the only language I know of with globally decidable type inference, and uses the similar hindley-milner method as Rust... but no doubt some of Rust's language features can break global inference. In Haskell, many common language extensions can also break global inference.

I think if Haskell was written today they probably wouldn't pick global inference as a goal, Haskell "best practice" types the function boundaries in the same way that Rust enforces.

Re: Haskell is our first choice for building production soft... by pcstl on Monday January 11, 2021 @07:48PM (#25740697)
SML and OCaml also have global inference, and in fact Haskell initially got it from there.

A lot of the "weirder" parts of Haskell are there because early on Haskell was pretty much "LazyML" and then it started growing into something different.

Re: Haskell is our first choice for building production soft... by lostcolony on Monday January 11, 2021 @10:26AM (#25730136)
Because the computer being right 90% of the time when something is ambiguous doesn't preclude the programmer from understanding it (while still providing them a best guess at their intent for those times they don't), but DOES mean that the program doesn't assume the wrong thing that remaining 10%.
Re: Haskell is our first choice for building production soft... by Rusky on Monday January 11, 2021 @12:52PM (#25732774)
I am not sure where you got the idea that Rust error message suggestions lead to blindly copying 60+ character type specifications. They tend to be much more localized and understandable in my experience.
Re: Haskell is our first choice for building production soft... by jhayward on Monday January 11, 2021 @01:33PM (#25733569)
I got the idea by following the Rust tutorials and then making 'simple' programs, seeing the errors, going to Rust resources and getting the advice 'just cut and paste the expected type'. The expected types generally had 6-8 ':'s, and three to four deep nested type specifiers.
Re: Haskell is our first choice for building production soft... by Rusky on Monday January 11, 2021 @06:24PM (#25739547)
If a significant part of those types was just something like `std::collections::` or similar then I'm not sure I see the problem.

Suggestions should probably trim redundant prefixes like that, but recognizing standard library namespaces shouldn't be a big obstacle to understanding either.

Re: Haskell is our first choice for building production soft... by jhayward on Tuesday January 12, 2021 @10:06AM (#25747808)
I haven't been back to rust since, so I don't have the specifics. But it was clear to me that this was not a helpful way to program.

It was also crystal clear that, like C++, Rust puts many barriers to true abstraction. You have to know many, many details of how a specific type is implemented, sometimes several levels deep, to correctly use it at a high level. The cognitive overhead is enormous.

Re: Haskell is our first choice for building production soft... by Rusky on Tuesday January 12, 2021 @11:50AM (#25749516)
In Rust's target domain(s), those details often turn out to be quite relevant.

Hiding them basically amounts to targeting a different domain. This is very different from being irrelevant and noisy.

Re: Haskell is our first choice for building production soft... by emteycz on Monday January 11, 2021 @07:45AM (#25728165)
That's not entirely true. It gives suggestions in the cases where the C++ compiler does too. There are more than a few very cryptic errors you can encounter with Rust. I like it though, just needs more work.
Re: Haskell is our first choice for building production soft... by 3836293648 on Monday January 11, 2021 @08:37AM (#25728670)
Depends on the compiler. In my very limited experience I've found that Clang is far superior to GCC in this matter (but rustc is better still, apart from iterator errors)
Re: Haskell is our first choice for building production soft... by srean on Monday January 11, 2021 @09:54AM (#25729586)
I am curious about which GCC, G++ version you have in mind. Clang definitely took the lead, but by GCC caught up and I prefer GCC's do Clang. But even I am behind the bleeding edge quite a bit so not sure how things stand now.
Re: Haskell is our first choice for building production soft... by leshow on Monday January 11, 2021 @11:59AM (#25731758)
It's been a while since I used C++ but I have never seen suggestions of the same quality that the rust compiler produces. Do you have a link that shows the error messages you're talking about?

For sure though, not every error has a great message and some can be cryptic. But those cases are relatively rare these days IMO

Re: Haskell is our first choice for building production soft... by MaxBarraclough on Monday January 11, 2021 @07:35AM (#25728076)
I don't agree here. As someone who's only ever dabbled with Haskell, I found its error-messages pretty cryptic, no better than C++. Perhaps they make more sense to someone with significant Haskell experience.

For what it's worth, I believe modern C++ compilers give much better error messages than older ones.

Re: Haskell is our first choice for building production soft... by ashtonkem on Monday January 11, 2021 @10:41AM (#25730366)
Haskell error messages are far less verbose, but I find them hard to read. What makes it worse is that often the error message involves a lot of deeply nested types that were hidden from me before by library writers using an alias. So I’ve had a lot of “where did that come from?” moments.
Re: Haskell is our first choice for building production soft... by brundolf on Monday January 11, 2021 @12:24PM (#25732226)
I had this problem when being onboarded into a TypeScript codebase recently. Unfortunately I don't think there's a technical solution to it: the type system simply won't stop you from making types that are way too complicated (unless you use a language like Go where the type system is intentionally lobotomized, which obviously comes with its own problems).

We're used to avoiding complexity when it comes to logic, but maybe there's less awareness when it comes to types. Maybe what we need is to have a bigger conversation around that so people realize it's something that needs to be on their radar.

Re: Haskell is our first choice for building production soft... by chc on Monday January 11, 2021 @01:01PM (#25732933)
The thing is, these types aren't usually complex in the way that logic is. Complex logic generally means lots of loops and conditions and such, maybe shared mutable state. Linear code that just calls a series of independent functions one after another is not generally considered complex, even though it may ultimately result in the execution of lots of code. What generally leads to these confusing errors is just simple types composed end-to-end. The problem is that while compilers are good at picking out the specific part of a function that's causing problems, they generally can't do the same thing with types, so it's kind of like if every time you got an exception, the entire module source was pinpointed as the problem.
Re: Haskell is our first choice for building production soft... by 91edec on Monday January 11, 2021 @12:32PM (#25732423)
Typescript needs some work on displaying type error messages, often the last line is all that needs to be read.
Re: Haskell is our first choice for building production soft... by brundolf on Monday January 11, 2021 @12:38PM (#25732512)
Type systems are really good for detecting contradictions; they're much less good at figuring out which piece should be different. For any given type error, there may be half a dozen different changes to the code that would resolve it in different ways. Type systems often have no real way of guessing the user-intent there. There are loose heuristics, like... an explicit return type is more likely to be intentional (and therefore correct) than the type of the local value that's being returned. But I'm not aware of any formalism around this "ranking" of which types are most likely to be unintentional. Maybe we need one.

The only immediate solution I can see is to keep types simple enough that the user can fit the entire relevant type-space in their head (and in the IDE dialog!), so that they themselves can determine which part is actually "wrong" (as opposed to just contradictory).

Re: Haskell is our first choice for building production soft... by pjmlp on Monday January 11, 2021 @07:49AM (#25728191)
Not only do modern compilers give better error messages (with room for improvement still), it is possible to make use of enable_if and if constexpr/static_assert to give proper error messages for templates, and when C++20 gets widespread enough, concepts.
Re: Haskell is our first choice for building production soft... by dkersten on Monday January 11, 2021 @10:27AM (#25730147)
Modern clang (usually, there are edge cases) gives pretty good error messages over all. And like you point out, if you use constexpr you get even better messages. Hell, I watched some cppcon videos over the weekend and learned that clang can even detect out of scope access of temporaries when in a constexpr (but not otherwise sadly), and also that in many cases, a lot more of a program can probably be constexpr than we might think.

The talks were by Jason Turner, who has an ARM emulator implemented entirely as constexprs and a test suite that runs at compile time (so if it compiled, the tests passed). Obviously for actually interacting with it, its not running at compile time, but the logic has the ability to run at compile time, which is pretty cool.

Re: Haskell is our first choice for building production soft... by pjmlp on Monday January 11, 2021 @10:40AM (#25730348)
Jason Turner has very cool talks, check the C64 one if you still haven't watched it.
Re: Haskell is our first choice for building production soft... by dkersten on Monday January 11, 2021 @12:31PM (#25732380)
I haven’t watched that one yet, thanks for the recommendation! I’ll give it a look tonight.
Re: Haskell is our first choice for building production soft... by dmitriid on Monday January 11, 2021 @01:10PM (#25733105)
I personally call it "old school" vs "new school".

"Old school" is asically the programming languages that originated in the 70s-80-90s. An incorrect but an illustrative way to describe error messages for them is "The programmer needs to suffer". They are any combination of cryptic, terse, complex, exposing internal machinery of the compilers and linkers etc. There are many reasons for this: computers were not powerful enough to afford better code analysis, parsing, backtracking etc; the users of the tools also knew the tools and could tinker with them etc.

"New school" is from late 2000s on. I usually say it started with Elm. Clear messages pinpointing the exact problem, solutions to problems inside error messages, error clarity as one of the priorities in language/compiler/tool design.

Re: Haskell is our first choice for building production soft... by pjmlp on Monday January 11, 2021 @03:09PM (#25735728)
Some of it caused by too much reliance on tools like yacc.

Category grammars were much better but more resource demanding, just like proper ASTs instead compiling as one goes.

Ironically there were already some attempts to Smalltalk like tooling for C++ back then, but again as you mention too much resource constraints.

Re: Haskell is our first choice for building production soft... by js8 on Monday January 11, 2021 @06:17AM (#25727452)
Actually, the reason why I found static typing annoying in the past (and why I felt more productive in Python) were the types are really low level (missing basic things like tuples) and lack of type inference. You have to repeat the type information, a lot. And also you have to declare lot of intermediate data structures.

In Python, this became easier and one could focus on the data transformations, thinking about the code a level higher.

But then I learned a bit of Haskell 5 years ago, and with type inference, this problem goes away. So it convinced me back to benefits of static typing. (Although I still feel the most productive in Python, their library APIs are IMHO unmatched in any language. But Haskell is catching up.)

Re: Haskell is our first choice for building production soft... by KingOfCoders on Monday January 11, 2021 @06:25AM (#25727510)
I've joined several companies, and getting into a Python code base was the most difficult one, because of the lack of typed method parameters. It was easier with Java and better still with Scala - same for Typescript vs. Javascript. I would be interested, is your Python experience green field or joining a large project? (just wanting to know, not implying anything on your part).
Re: Haskell is our first choice for building production soft... by jim-jim-jim on Monday January 11, 2021 @06:46AM (#25727679)
I had the exact same experience: being a new employee at companies A and B, with large Python and Scala codebases respectively. At company B it was far easier to get on board and start writing code, and it has remained easy. Trying to make sense of Python was truly demoralizing, and a significant part of why I left company A.
Re: Haskell is our first choice for building production soft... by wassenaar10 on Monday January 11, 2021 @10:03AM (#25729754)
> getting into a Python code base was the most difficult one, because of the lack of typed method parameters

Yup, this is probably my main issue with Python. I love writing it when I'm working on personal projects, having to read massive Python code bases at work feels unnecessarily tedious due to how much work you have to do sometimes just to find out the type of something.

Re: Haskell is our first choice for building production soft... by js8 on Monday January 11, 2021 @06:42AM (#25727647)
It was an experience on my personal projects, cca 20 years ago. That's when I started using Python and it really felt more powerful than C++ (and Java) back then. Then around 2008 I became interested in Common Lisp, and then later I made the choice to learn Haskell instead of Clojure. It took me a while before actually getting where is the improvement in Haskell and functional programming. This was all for my own personal projects, which are small programs.

I would still recommend against using Python on a big project. Funny thing, I remember talking to my boss (a mainframe programmer) in 2010, when I solved something with a script in Python, that I wouldn't use it in production, but it's great for small things. Forward to 2020, plenty people use it in products. Maybe the Haskell will be the same, you also have many people today saying "well this is good for experiments but I wouldn't write a product in it".

Re: Haskell is our first choice for building production soft... by mumblemumble on Monday January 11, 2021 @09:50AM (#25729516)
I bounced off of Python a few times before finally taking to it (at a time when I had no choice). I honestly believe that this situation has improved since Python 3.5 or so, purely on the basis of improved standards of documentation, including many more libraries adding type hints to their public interfaces.

I've recently been back to Clojure, and it's the same old aggravation again. It seems that, oftentimes, the only way to know what arguments a function is prepared to accept is to already know what arguments a function is prepared to accept.

I don't want to come across as being too down on dynamic typing - I'm currently in the process of trying to get my company over to Python by any means necessary. What I really want to challenge is the idea, popular in many dynamic typing circles, that static types just get in the way. They can also serve to communicate essential information. If you aren't communicating that information through type annotations, then it's absolutely essential that you do it by some other means.

Re: Haskell is our first choice for building production soft... by ithrow on Monday January 11, 2021 @02:41PM (#25735150)
I don't want to come across as being too down on dynamic typing - I'm currently in the process of trying to get my company over to Python by any means necessary.

Curious, from what and why? ML?

Re: Haskell is our first choice for building production soft... by neutronicus on Monday January 11, 2021 @10:32AM (#25730210)
I worked on a large-ish C++/Python codebase and touching the Python parts was always extremely frustrating for me.

The lack of .h files alone is a huge grievance for me - I had to scroll past definitions even to know names and arities of class methods, read constructors to know what's in class members.

SciPy was nice enough for turning data into a picture, though.

Re: Haskell is our first choice for building production soft... by supergarfield on Monday January 11, 2021 @10:48AM (#25730479)
> The lack of .h files alone is a huge grievance for me

That's an interesting point... Besides C and its derivatives, and OCaml, do other languages have separate definition files? It seems like newer languages, even statically typed, normally don't.

I suspect the reason is that you have to duplicate all definitions, which seems like rote work. It also feels less necessary with IDE tooling: IDEs I know have a view for all definitions in a file.

Re: Haskell is our first choice for building production soft... by mumblemumble on Monday January 11, 2021 @11:17AM (#25730972)
They don't, but, at least in object-oriented languages, much of overall experience is easy enough to replicate with formal interfaces and coding standards.
Re: Haskell is our first choice for building production soft... by KingOfCoders on Monday January 11, 2021 @11:30AM (#25731223)
I thought the nice thing about Modula-2 was that you could browse through interface files to understand some code and then go into implementations.
Re: Haskell is our first choice for building production soft... by mumblemumble on Monday January 11, 2021 @11:37AM (#25731351)
It's true, but there are so many ways to skin that cat. Smalltalk, for example, gives an even more fluid way to browse at a high level and then drill in, and it doesn't (necessarily) have source code files in the first place.
Re: Haskell is our first choice for building production soft... by dehrmann on Monday January 11, 2021 @12:55PM (#25732837)
> getting into a Python code base was the most difficult one, because of the lack of typed method parameters

One place I worked used to be a Python shop, but had migrated most of its services to Java. Chatting with one of the engineering leads for a large Python system that had a lot of business logic, he said where Python actually fails to scale is lines of code and developers because lack of types makes it harder to reason about and harder to make changes safely. This obviously changed now that type annotations are a thing.

Re: Haskell is our first choice for building production soft... by mattnewton on Monday January 11, 2021 @12:28PM (#25732332)
For new python work that might grow, I highly recommend pytype annotations. It’s not perfect but it’s as close to the best of both worlds that I have ever seen in production.
Re: Haskell is our first choice for building production soft... by gameswithgo on Monday January 11, 2021 @08:49AM (#25728797)
there are controlled studies supporting this idea the function parameters not having types slows down productivity
Re: Haskell is our first choice for building production soft... by tome on Monday January 11, 2021 @09:05AM (#25728961)
It would be helpful if you linked them ...
Re: Haskell is our first choice for building production soft... by WraithM on Monday January 11, 2021 @08:45AM (#25728753)
I appreciate that you wrote that you "feel" more productive with python. I 100% agree with this feeling at most scales of code size, and the feeling matches reality at the small scale. However, I've found that this feeling of productivity doesn't match reality in the large. I use Haskell for programming in the large despite this feeling of unproductivity, because in fact, I am way more productive.
Re: Haskell is our first choice for building production soft... by js8 on Monday January 11, 2021 @09:43AM (#25729402)
Just to clarify, I agree that Haskell can be more productive than Python, I was talking about productivity of Python (or, for that matter, Lisp) compared to C-like languages of the era. But with Haskell's type inference, the Python's advantage is lost (if we forget, for a moment, extremely well-designed Python's standard library with focus on convenience).
Re: Haskell is our first choice for building production soft... by bcrosby95 on Monday January 11, 2021 @12:31PM (#25732384)
> in the large

At what point do you feel like this line is crossed? "In the large" can mean different things to different people.

Re: Haskell is our first choice for building production soft... by WraithM on Tuesday January 12, 2021 @09:37AM (#25747422)
100k+ lines
Re: Haskell is our first choice for building production soft... by jcelerier on Monday January 11, 2021 @06:21AM (#25727482)
> the types are really low level (missing basic things like tuples) and lack of type inference

how far ago was this in the past ? C++ had tuples and type inference for ten+ years officially now - gcc 4.4 had it in 2009

Re: Haskell is our first choice for building production soft... by thesz on Monday January 11, 2021 @11:09AM (#25730800)
C++ cannot have non-local type inference due to, you know, object-oriented part of it.

This means that you cannot say something like this:

  auto sepulka;
  auto bubuka = zagizuka(sepulka);
Because if zagizuka's parameter is a structure or a class, you have a selection of parents. On a contrary, you have a selection of descendants of the result type of zagizuka() for bubuka, each having their own copy or assignment constructor.

[1] http://lucacardelli.name/Talks/2007-08-02%20An%20Accidental%...

[2] https://en.wikipedia.org/wiki/Intuitionistic_type_theory#Mar...

[1] shows how hard it is to make right type system with inheritance. I believe these slides mention 25 years of collaborative effort. Compare that to [2] where it took 8 years to design intuitionistic type theory (1971-1979) by mostly single person.

Re: Haskell is our first choice for building production soft... by gpderetta on Monday January 11, 2021 @12:47PM (#25732683)
C++ doesn't have type inference at all which I understand requires constraint solving.

It has a much simpler type deduction system where the type of an object is deduced from its initializing expression, i.e. deduction always flows in one direction.

It is nowhere as powerful, but it does cover a lot of use cases.

One advantage (in addition to the ease of implementation) is that, except for circular definitions, there are no undecidable cases and it is not necessary to restrict the type system to prevent them.

Re: Haskell is our first choice for building production soft... by andrekandre on Monday January 11, 2021 @04:20PM (#25737249)
not that im advocating it per se, but couldnt you deduct the tyope based on what `zagizuga()` does with `sepulka`?

for example

  def sepulka(zagizuga)
    zagizuga.doSomething()
    zagizuga.doSomethingElse()
would infer the type of zagizuga as some object that implements two methods `doSomething()` and `doSomethingElse()`... i think that should be doable (and possibly extremely slow) right?

maybe i missed something...

Re: Haskell is our first choice for building production soft... by thesz on Tuesday January 12, 2021 @10:42AM (#25748299)
Yes, it is doable, but what if there several memory-layout incompatible classes which implement both methods?

E.g, A implements virtual doSomething() and B and C inherit from A, add some different fields and both implement doSomethingElse() which they should overload for their inheritance from class Z.

Re: Haskell is our first choice for building production soft... by andrekandre on Tuesday January 12, 2021 @12:27PM (#25750091)
good question, i guess it depends on the language... multiple inheritance without namespacing would either result in either method getting chosen randomly, or a build error...

for example, in swift you cant even inherit from two protocols that have default implementations... and i think in c++ you also cant call the method without specifying namespace...

so, i suppose, if you wanted to go all the way, you could even do namespace inference

  def sepulka(zagizuga)
    zagizuga::Something.doSomething()
    zagisuga.doSomethingElse()
so zagizuga is infered to be some type that inherits from `Something` namespace and expects that namespace to defined `doSomething()` function, in addition to providing `doSomethingElse()`

though that seems getting a bit fragile irl maybe...

Re: Haskell is our first choice for building production soft... by mjburgess on Monday January 11, 2021 @06:27AM (#25727526)
There's also the culture around the language to fold in.

A culture of writing code assuming inference and structural typing is quite different than it merely being available.

Re: Haskell is our first choice for building production soft... by FpUser on Monday January 11, 2021 @07:44AM (#25728154)
I have zero problems using type inference, tuples, etc in my code. Other developers I deal with and who do use C++ have no problems using those "novel" concepts either. So I am completely at loss about what type of culture you are talking about here. It looks like grasping at a straw type of argument to me.
Re: Haskell is our first choice for building production soft... by mjburgess on Monday January 11, 2021 @08:32AM (#25728622)
I'm talking about all libraries and books written since it's development up until the early 10s; and of all those teams, libraries, and code which are legacy.

Haskell has never had a decades-long history of 'compiler-oriented programming', ie., excessive declarations, and so on.

The idea that C++ has a haskellish culture is patently absurd, even if the vanguard regard itself as presenting tending toward that direction.

Re: Haskell is our first choice for building production soft... by FpUser on Monday January 11, 2021 @12:12PM (#25731987)
I am in no way implying that "C++ has a haskellish culture". Neither I would consider it of any advantage. All I said is that modern C++ programmers have no problems using the concepts. There is plenty of those that are used in gobbles of libraries as well. Sure old libraries do not have it but so what?
Re: Haskell is our first choice for building production soft... by sfg on Monday January 11, 2021 @07:34AM (#25728058)
So, OCaml or something?

Or has Haskell added structural typing?

Re: Haskell is our first choice for building production soft... by mjburgess on Monday January 11, 2021 @09:07AM (#25728983)
Haskell is structurally typed...
Re: Haskell is our first choice for building production soft... by tome on Monday January 11, 2021 @09:13AM (#25729044)
Hmm, what do you mean? Haskell is generally considered nominally typed (or rather types introduced by its newtype and data declarations are ...). "Structural typing" typically refers to things like polymorphic row types and polymorphic variants.
Re: Haskell is our first choice for building production soft... by mjburgess on Monday January 11, 2021 @10:53AM (#25730557)
Sure, my mistake. I meant something looser.

Only that the types can be analysed structurally (ie., pattern matched).

In C++, etc. there's a "radical nominalism" in which the type was very opaque, ie., encapsualated.

Re: Haskell is our first choice for building production soft... by gpderetta on Monday January 11, 2021 @12:53PM (#25732792)
It is complicated. Templates do allow some form of structural typing and the new-in-C++17 structured bindings do allow for decomposing and inspecting types (although this being C++ it is kind of awkward). Structured bindings are expected to evolve into full pattern matching in the future.
Re: Haskell is our first choice for building production soft... by mehrdadn on Monday January 11, 2021 @07:33AM (#25728056)
> You have to repeat the type information, a lot.

Nope you don't, that's what typedefs are for. They're underrated for sure though. People don't use them nearly as much as they should. They're incredibly valuable for avoiding precisely this problem.

Re: Haskell is our first choice for building production soft... by nicoburns on Monday January 11, 2021 @07:38AM (#25728099)
That doesn't stop you having to type e.g.

String foo = "bar"; String baz = foo;

The `String`s can be completely avoided in languages with type inference because it's obvious that a string literal is a string.

Re: Haskell is our first choice for building production soft... by mehrdadn on Monday January 11, 2021 @07:48AM (#25728184)
I thought the complaint was about the logic duplication, not the extra keystrokes. If you want type inference you already have auto. If you want to minimize your keystrokes, you're using the wrong language to begin with, whether there's type inference or not. C++ is designed for writing software robustly, not quickly. (<-- This is not a trivial or obvious statement btw. It took me several years to grasp this. And I viewed C++ from an entirely different perspective when it finally sunk in for me that I would appreciate C++ much more if I decided to make minimizing keystrokes a non-goal.)
Re: Haskell is our first choice for building production soft... by secondcoming on Monday January 11, 2021 @07:56AM (#25728265)
> If you want type inference you already have auto

or auto&&. Did you really intend to make a copy?

Re: Haskell is our first choice for building production soft... by mehrdadn on Monday January 11, 2021 @08:01AM (#25728307)
You probably did intend it to be a copy if you're binding it to a variable and need it to be non-const (like in the example)!
Re: Haskell is our first choice for building production soft... by secondcoming on Monday January 11, 2021 @08:18AM (#25728483)
Ah, but you knew that because that's how the code was written!

If it was instead

    String foo = "bar";
    auto baz = foo;
you don't know for sure. But the code compiles so it obviously ok!
Re: Haskell is our first choice for building production soft... by mehrdadn on Monday January 11, 2021 @08:22AM (#25728521)
No, I'm saying even in that case you know it was intended to be a copy. If you wanted that to be a reference then you'd either (a) just do the obvious thing which is to just use the original variable name instead of creating a new variable out of the blue for no reason, (b) leave a comment explaining why you're not doing the aforementioned obvious thing, or (c) use a self-explanatory variable name to provide the explanation instead of a comment.
Re: Haskell is our first choice for building production soft... by UweSchmidt on Monday January 11, 2021 @07:54AM (#25728241)
Is it really that painful to write "String" each time? You spend at least a fraction of a second anyway to verify that you're writing the right thing, to reconsider if you should use an object or constant or refactor the function to work with a Boolean instead of a naked string; why is writing out the type such a big deal everytime this topic comes up?

I remember my first attempts at programming and being annoyed that I can't add a string and an int; ever since that little bit of housekeeping of using types made sense to me and I can clearly see how it eliminates entire classes of errors.

Re: Haskell is our first choice for building production soft... by wtetzner on Monday January 11, 2021 @11:27AM (#25731172)
> Is it really that painful to write "String" each time?

I find it more painful to read code that has too many type annotations. I also find it painful to read code that has too few, so I'd argue there's a bit of an art to it.

But languages that have type inference but allow type annotations at least allow you to try to hit that balance.

Re: Haskell is our first choice for building production soft... by leshow on Monday January 11, 2021 @12:11PM (#25731980)
> I remember my first attempts at programming and being annoyed that I can't add a string and an int; ever since that little bit of housekeeping of using types made sense to me and I can clearly see how it eliminates entire classes of errors.

Type inference doesn't make these errors go away.

And about your other point, it's unfair to look at just a simple case of writing "string" or not as the only thing inference provides. Although I'd argue that leaving out types where possible helps readability-- it's really the more elaborate cases or intermediate steps during a longer transformation that inference helps with. Not to mention the fact that inference in closures is also really nice.

Re: Haskell is our first choice for building production soft... by silluk on Monday January 11, 2021 @11:25AM (#25731130)
To me it's not the trivial cases like this that make type inference useful. It's when you get longer types like `Arc<Mutex<HashMap<String, String>>>`. Granted, that could be solved with a `type` declaration (or `typedef` in C++) but it's still convenient to be able to say: `let mut x = Arc::new(Mutex::new(HashMap::new()));` and let the compiler figure out the rest based on usage.
Re: Haskell is our first choice for building production soft... by oblio on Monday January 11, 2021 @07:45AM (#25728159)
Java now has (limited) type inference, bar. As does C++, auto. They're limited but they remove a lot of tedium.
Re: Haskell is our first choice for building production soft... by secondcoming on Monday January 11, 2021 @07:55AM (#25728255)
And it's my experience that that is only a benefit to the person who wrote the code, and only for a short time.

Generally, I prefer being able to read a line of code and understanding exactly what it does. If I need an IDE and have to repeatedly try to find the definition of something then, in my opinion, that's wasting my time.

C++'s 'auto' is really useful but it's over-used IMO. I think that there's a belief that if you're not using 'auto' everywhere then you're not writing 'modern' C++. Just becuase your code compiles doesn't necessarily mean it's correct.

Re: Haskell is our first choice for building production soft... by mehrdadn on Monday January 11, 2021 @08:18AM (#25728488)
+1 for auto being overused. I always felt I was shouting into the void (hah) by saying the same thing... it's nice to see someone else agrees.
Re: Haskell is our first choice for building production soft... by nicoburns on Monday January 11, 2021 @11:33AM (#25731277)
I find that types can reduce readability as well as enhance it. They add noise and make it harder to concentrate on the variable names which are often much more important than the types which are often (but certainly not always) obvious from context.
Re: Haskell is our first choice for building production soft... by secondcoming on Monday January 11, 2021 @03:26PM (#25736091)
Interesting point.

I'd never have believed it myself, but find myself using acronyms instead of variable names when the type allows it.

    void foo(MyType mt, const MyOtherType& mot);
It's the variable names that are the noise, types are everything. And no, it's not Hungarian notation either in case anyone suggests it!

However, it maybe doesn't work that well with things like class member names. YMMV

Re: Haskell is our first choice for building production soft... by nicoburns on Monday January 11, 2021 @05:22PM (#25738325)
I guess it partly depends on how varied your types are. In some domains you can find yourself working with 10 variables that are all strings, or all floats/integers. At that point the type isn't that helpful for distinguishing which variable is which.
Re: Haskell is our first choice for building production soft... by secondcoming on Tuesday January 12, 2021 @05:58AM (#25745162)
I should have added that fairly liberal use of type aliases also helps.

    using B64String = std::string;

    B64String encode(const std::string& text);
    std::string decode(const B64String b64);
Re: Haskell is our first choice for building production soft... by corty on Monday January 11, 2021 @08:57AM (#25728886)
Code that specifies types instead of using auto is, barring compiler bugs, usually less correct. The compiler knows better than you what the type really is.
Re: Haskell is our first choice for building production soft... by msla on Monday January 11, 2021 @08:00AM (#25728299)
Shifting topics a bit, typedefs don't allow me to write generic code. Templates do, but templates bring in their own problems, in addition to not being expressive in the right ways: I can have an array of T, but I can't specify that T is Numeric?

The fact C++ doesn't have Numeric but instead has int and long and unsigned and long long and float and double all off on their own is another problem: The compiler knows enough about them to have complex promotion rules but doesn't know enough to allow me to refer to all of them under one name in my code.

Re: Haskell is our first choice for building production soft... by mehrdadn on Monday January 11, 2021 @08:12AM (#25728414)
You're asking for the impossible. What you want is precisely what templates are, but you also want them to not be "templates" for... some bizarre reason.

> I can have an array of T, but I can't specify that T is Numeric?

Sure you can. If you have C++20 concepts:

  template<class T>
  concept Numeric = std::integral<T> || std::floating_point<T>;
  
  template<Numeric T>
  T twice(T x)
  { return x + x; }
Or if you're on a C++11 compiler:

  template<class T>
  typename std::enable_if<
    std::is_arithmetic<T>::value,
    T>::type twice(T x)
  { return x + x; }
Re: Haskell is our first choice for building production soft... by jcelerier on Monday January 11, 2021 @08:49AM (#25728802)
the C++ 20 version can be simplified a bit to:

    Numeric auto twice(Numeric auto x)
    { return x + x; }
Re: Haskell is our first choice for building production soft... by mehrdadn on Monday January 11, 2021 @03:20PM (#25735949)
Probably not a good idea since the caller won't know what the return type is at that point, and the return type would become dependent on the implementation, which breaks function abstraction.

And imagine what would happen when you get a few more 'auto' variables in the return expression. Suddenly your return type will depend on the implementation of your callees. And the code can then quickly become impossible to understand.

auto is overused.

Re: Haskell is our first choice for building production soft... by jcelerier on Monday January 11, 2021 @04:31PM (#25737455)
> Suddenly your return type will depend on the implementation of your callees

Why would that be a problem ? It's super common in templates and has never troubled me the least

Re: Haskell is our first choice for building production soft... by mehrdadn on Monday January 11, 2021 @04:57PM (#25737913)
It might be common practice but it shouldn't be. There are lots of reasons this is a bad idea; here's just a sampling:

1. "My return type is whatever I happen to return" circumvents the ability of the type checker to ensure correctness.

2. More generally, the purpose of a specification (a function declaration in this case) is to declare what is required of a compliant implementation, and to provide a way to check the validity of that implementation. But when you make the types all become auto-deduced, you're basically reducing the specification to a ~ shoulder shrug "it does whatever it does" ~.

3. Moreover, as I alluded to in the comment, it quickly becomes near-impossible to meaningfully separate the definition from the declaration, whether that's because you want to hide it or because you want to compile it separately. Simply put, you lose modularity. It seems like a minor thing when (as in the example) the return value doesn't depend on types inferred from other callees' return values, but as soon as that ceases to be true, you suddenly tie together the implementations of multiple functions. At that point, your functions lose much of their power to abstract away anything, since as soon as you change the return expression for one function, it has the potential to break code (up to and including causing compilation errors) in the the entire chain of callers. (!)

4. Templates end up getting re-instantiated far more often than they need to be (which can slow down both the compilation and the runtime efficiency). You almost certainly don't want '0' and '(size_t)0' to result in duplicate instantiations when dealing with sizes, for instance.

5. Issue #4 can also result warnings/errors/bugs, since now you have a function that returns a different concrete type than you likely intended, which can result in everything from spurious warnings (signed/unsigned casts, for instance) to actual bugs (later truncation of other variables whose types were inferred incorrectly as a result).

6. The code becomes difficult for a human to read too. You now no longer have any idea what types some variables are supposed to be. Not only does this hamper your ability to cross-check the correctness of the implementation itself (just as with the declarations, in #1) but unless your function is trivial, this quickly makes it harder to even understand what the code is doing in the first place, never mind what it's supposed to do.

7. Proxy types become impossible to implement, since they won't undergo the intended conversions anymore.

All this just to reduce keystrokes might be a common trade-off, but a poor one. I can come up with more reasons, but hopefully this gets the point across.

Re: Haskell is our first choice for building production soft... by msla on Monday January 11, 2021 @09:56AM (#25729613)
Bah. Leave it to the latest versions of C++ to show me up.
Re: Haskell is our first choice for building production soft... by dkersten on Monday January 11, 2021 @10:32AM (#25730212)
That's the point though, isn't it? To improve on areas that were lacking in older versions. It can be hard to keep up, though!
Re: Haskell is our first choice for building production soft... by mehrdadn on Monday January 11, 2021 @02:05PM (#25734394)
It's not just the latest version though? C++11 could already do what you wanted.
Re: Haskell is our first choice for building production soft... by MaxBarraclough on Monday January 11, 2021 @08:14AM (#25728438)
edit: I see dataflow beat me to it. I'll leave this here anyway.

> I can have an array of T, but I can't specify that T is Numeric?

This is what type-traits and 'concepts' are for, right?

> The compiler knows enough about them to have complex promotion rules but doesn't know enough to allow me to refer to all of them under one name in my code.

This is what std::is_integral gives you.

https://en.cppreference.com/w/cpp/types/is_integral

Re: Haskell is our first choice for building production soft... by avl999 on Monday January 11, 2021 @06:19AM (#25727468)
> the reason they "find that the compiler feels like an annoyance" is because their first exposure to Java / C++ is in school where they have an assignment due for tonight and the compiler won't stop banging pages of errors about std::__1::basic_string<char, std::__1::allocator<char>> and what the fuck is that shit I just want to make games !!11!1!

Well I can't imagine how much more annoyed they'd be when using an interpreted language which lets the code run just fine but then fails at runtime in mysterious and subtle ways requiring hours of manually scanning though code and print statements when the compiler would have caught a decent subset of those errors with helpful messages about the exact line they need to fix.

Re: Haskell is our first choice for building production soft... by dan-robertson on Monday January 11, 2021 @06:41AM (#25727646)
I feel like it probably isn’t worthwhile to litigate the merits of static typing every time there is a HN post that’s vaguely adjacent to the topic.

For the amount people care about it, there isn’t much evidence in either direction. And most studies that do exist are limited to small programs typically written by novices. Yale’s Singapore campus are going to be running two instances of the same course in parallel soon, one in python and one in ocaml. Perhaps that will provide a datapoint about learning the languages but maybe there will just be a lot of selection bias or library or environment or teacher differences. And how easy it is to learn a language probably isn’t the main datapoint to care about anyway.

Re: Haskell is our first choice for building production soft... by ernst_klim on Monday January 11, 2021 @07:03AM (#25727821)
> there isn’t much evidence in either direction

Oh, I think there are great evidences, such as: dialyzer, or ruby3 and python3 shifting towards type signatures everywhere and gradual typing, or recent racket focus on typed racket. Oh, and the rise of typescript of course.

I mean, I've abandoned Python years ago, and I was quite surprised when I discovered python people are adding type annotations everywhere.

Sure, gradual typing is not a strictly enforced as in statically typed languages, but seems people are agree that modularity and abstraction without type signatures is painful in sufficiently large programs.

Re: Haskell is our first choice for building production soft... by dan-robertson on Monday January 11, 2021 @07:23AM (#25727969)
What you have described is an anecdote rather than any study that attempts to be impartial which is what I really meant when I wrote ‘evidence.’ I’m sorry for not being clear enough.

I don’t feel like this anecdote is evidence because I don’t think it’s inconsistent with the trend towards more static types over the last 5-10 years or so. For this anecdote to be convincing I would need to think that programming language design happens because of carefully thought out and researched decisions and quick feedback as good languages are used and bad languages are dropped, but I don’t believe this.

Re: Haskell is our first choice for building production soft... by ernst_klim on Monday January 11, 2021 @07:47AM (#25728176)
This is not an anecdote by definition, since these languages represents quite a huge marketshare (and most of the rest langs are already statically typed).

Yes, this is not a sound rigid empirical proof, it's an observation (i.e. unlike the case of anecdotal, you can measure the marketshare of user, how many do use dialyzer or typescript, etc etc). We can't simply ignore any observations that are not scientifically rigid, otherwise the whole edifice of philosophy or even some natural sciences should simply perish.

I don't think you can just omit that. I'm a fan of Lakatos here, if I have some observation, I think one need at least as convincing evidence or more rigid one to prove otherwise.

> because of carefully thought out and researched decisions

I think it's a better evidence exactly because it's what language users are asking about, and what large chunk of language users choose to use when they got a choice. This shows that quite a big share if not majority of programmers value type annotations.

Re: Haskell is our first choice for building production soft... by dan-robertson on Monday January 11, 2021 @08:10AM (#25728394)
> I think it's a better evidence exactly because it's what language users are asking about, and what large chunk of language users choose to use when they got a choice. This shows that quite a big share if not majority of programmers value type annotations.

To be clear, this is where I disagree. I don’t want to claim that people don’t think hard about language design or that users aren’t asking for these features as I think both of those statements are true. But I strongly disagree that languages doing things (and those languages being popular) is good evidence that those things are good.

I think a lot of language design is driven by fashion (ie keeping up with what similar languages are doing) and I claim that this is a more convincing reason for python having some gradual typing.

I think large number of people is moving to/from from python for gradual typing in aggregate, and I don’t think it’s happening on the margin either. I think any wise decisions about languages are more likely to be driven by practical considerations (what do people know, what are they used to, what can people be hired for, what libraries are available, what platforms are supported, what performance is required, and so on).

Just because python has a large market share, it doesn’t mean it’s users are supporters of gradual typing, it just means that they thought python was a good idea when they first started using it and they haven’t justified the cost of changing to something else. The users didn’t choose gradual typing they just chose “upgrade the language to the next version”

Even if I agreed with your claim that many users asked for gradual typing, I don’t agree that in aggregate users ask for things that will be good for them or good in general. Maybe users are just trying to figure out a way to say “we want our programs to be less buggy” and think this might help. I think there are better examples in programming language design of what can happen if you keep giving users what they are asking for.

Re: Haskell is our first choice for building production soft... by Guthur on Monday January 11, 2021 @06:50AM (#25727720)
It would if python actually encouraged runtime coding.

In my opinion dynamic programmers need to embrace the runtime environment and use it as part of their development methodology. Unfortunately most popular dynamic languages have woeful runtime environments.

Re: Haskell is our first choice for building production soft... by andrekandre on Monday January 11, 2021 @04:35PM (#25737550)
yep, i was going to say the same thing, the biggest issue with dynamic vs static is maybe people are missing the point:

dynamic languages (like smalltalk) were designed for live coding where the results are immediate, when that is broken and coding is done in a "dead" environment of course dynamic typing will cause problems that arent caught until runtime... but the original idea was one shouldnt have had to wait until runtime in the first place!

Re: Haskell is our first choice for building production soft... by sfg on Monday January 11, 2021 @08:49AM (#25728805)
So, Common Lisp and Smalltalk?

Any others?

Re: Haskell is our first choice for building production soft... by Guthur on Monday January 11, 2021 @04:56PM (#25737896)
I'd imagine some Scheme environments are good as well, like Dr Racket.

Unfortunately the same amount of effort that has been applied to static type checking has not been applied to dynamic language environments.

It would have been very interesting to see what could be possible with the more advancement.

Re: Haskell is our first choice for building production soft... by cjallen88 on Tuesday January 12, 2021 @04:50AM (#25744526)
Factor for sure
Re: Haskell is our first choice for building production soft... by bird_monster on Monday January 11, 2021 @06:22AM (#25727489)
> Well I can't imagine how much more annoyed they'd be when using an interpreted language which lets the code run just fine but then fails at runtime in mysterious and subtle ways requiring hours of manually scanning though code and print statements when the compiler would have caught a decent subset of those errors with helpful messages about the exact line they need to fix.

You cannot get mad at errors you don't know about.

Also letting the user find and report the error allows you to mark your tickets "done" and move on, which makes management happy.

Re: Haskell is our first choice for building production soft... by ZephyrBlu on Monday January 11, 2021 @06:25AM (#25727514)
In my experience, you quickly develop an intuition for where things are going wrong with interpreted languages.

Ex: "Oh, cannot access property x of undefined? Something must be going wrong in y object"

Python definitely feels a lot more helpful than JS though. Can't speak for other interpreted languages like Ruby.

Re: Haskell is our first choice for building production soft... by cjfd on Monday January 11, 2021 @06:40AM (#25727635)
The thing is, though, that you mostly only get errors for code that is actually executed. So, your program is only fully type checked when all code paths are executed. In the case of python one can ameliorate this situation a bit by using mypy. At my job I see very often code being broken because, e.g., the signature of a function was changed but not in all places and so on. Now somebody will say that the IDE can solve that but these colleagues who are regularly breaking the code are actually using IDEs and it somehow still does not help. I have come to think that code that is not compiled and/or otherwise type checked is just not very serious and certainly not worthy of production environments.
Re: Haskell is our first choice for building production soft... by pansa2 on Monday January 11, 2021 @07:04AM (#25727827)
> your program is only fully type checked when all code paths are executed.

The solution to this is to make sure that, during testing, all code paths are executed. And that’s something you should be doing anyway, to find bugs that aren’t type errors.

Re: Haskell is our first choice for building production soft... by dkersten on Monday January 11, 2021 @10:37AM (#25730300)
I've worked with Python codebases that had very extensive test suites and I've still encountered many cases of bugs slipping through that a static type check would have caught. Its really hard to make sure tests are fully comprehensive. About the best you could do is generative property-based tests, but then the feedback loop is not great as it may take minutes, hours, days or weeks for a particular problem case to be generated, while the static check would have caught it at compile time or even interactively in your IDE.

I don't hate dynamic languages, but this is a pretty major weak spot for them, in my personal opinion, and one that's bitten me a number of times.

Re: Haskell is our first choice for building production soft... by willtim on Monday January 11, 2021 @07:19AM (#25727934)
That is impossible with almost all non-trivial software. Testing proves only the presence of errors not their absence.
Re: Haskell is our first choice for building production soft... by neillyons on Monday January 11, 2021 @09:26AM (#25729171)
> Testing proves only the presence of errors not their absence.

I've never thought of it that way, but that totally makes sense.

Re: Haskell is our first choice for building production soft... by srean on Monday January 11, 2021 @10:02AM (#25729725)
You can think of the compiler for a statically typed language doing exactly that at runtime for a subset of potential errors -- the type errors. Some people claim that they never make them and they may well be correct. I do commit such errors so compiler is a friend, but a pedantic friend.
Re: Haskell is our first choice for building production soft... by cjfd on Monday January 11, 2021 @08:49AM (#25728807)
I am all for high test coverage. One should not underestimate the effort in that, though. Some time ago I covered some two thousand lines of code completely in tests. As in, all code paths, checking all side effects. Kind of an effort in the spirit of "dealing effectivly with legacy code" by Michael Feathers. They were quite non-trivial and it took me about two months. Doing such a thing may not always be feasible. Also if code is written by others they may have covered fewer code paths in tests than one would have liked. A type checker will check all code paths but the tests that your predecessor failed to write are not checking anything.
Re: Haskell is our first choice for building production soft... by jcelerier on Monday January 11, 2021 @06:28AM (#25727544)
having just spent an hour over vscode live share with a student who's learning javascript, I have a pretty good idea.

But I've worked with people who saw all compiler errors as things of the devil and wanted to defer as much as possible to runtime.

Re: Haskell is our first choice for building production soft... by kungito on Monday January 11, 2021 @06:31AM (#25727560)
faculty helps students debug their code?? where?
Re: Haskell is our first choice for building production soft... by jcelerier on Monday January 11, 2021 @06:35AM (#25727595)
I'm in france haha. why wouldn't you help a student who asks you kindly ?
Re: Haskell is our first choice for building production soft... by xdavidliu on Monday January 11, 2021 @07:40AM (#25728116)
Parent is probably referring to situations where faculty are too busy researching, writing grants, or just plain don't feel like it, and tell students something like

"go play with it"

"look it up"

"google it"

"read the fudging manual"

Of course, there are many great faculty who _do_ care greatly about teaching and always help students.

Re: Haskell is our first choice for building production soft... by LandR on Monday January 11, 2021 @07:01AM (#25727802)
At my Uni we had students from higher years do volunteer time during lab sessions for lower year students. You would just wander around the lab helping random people who were stuck.

Sometimes there would be some proffessors there too to help you out.

Re: Haskell is our first choice for building production soft... by dsign on Monday January 11, 2021 @08:16AM (#25728457)
Amen to that. I love dearly both C++ and Haskell, but I remember those times when I wanted to cry because the C++ error message broke the OS clipboard when I was trying to copy it to a text editor so that I could write a program to analyze it and find which "const" didn't match in the jungle of type names. I have never had that situation with Haskell.
Re: Haskell is our first choice for building production soft... by Vosporos on Monday January 11, 2021 @09:47AM (#25729473)
Oh dear :o
Re: Haskell is our first choice for building production soft... by labawi on Monday January 11, 2021 @05:40PM (#25738656)
> As a mostly C++ programmer making sure that I get compiler errors as often as possible by encoding most preconditions in the type system ..

When selecting a language for a recent project, that needed to run correctly, without extensive debugging that would be hard to simulate (too many states and interactions), I had a couple of important criteria:

0) checked static typing

1) ADTs (that are reasonably easy to use, read and write)

2) pattern matching (no way I'll get all the if/else right)

3) reasonably easy to write static const (pure functional) code

4) memory-safe

I've considered rust, but settled on haskell, as I needed it fast and I know haskell. While technically any Turing-complete language would work, I don't think C++ would be a fit for must-work code, even disregarding (4).

While I haven't used C++ in a while, it seems to me, encoding the constraints would be 3-10x as much code, or even more, with many checks/cracks left, and a lot of readability gone.

Clean and correct functional haskell code took a bit longer to write than say happy-path imperative python, but after fixing 2 or so bugs that manifested on pretty much the first (partial) use (like incorrect "<" vs. ">" and a bad constant), it has been running happily ever since. I didn't even bother simulating a full system configuration before a real-world customer acceptance test, because components worked on 1-2 inputs I tried, setting up a system would take a couple of hours and I couldn't think of reasonable failure scenarios. I haven't experienced similar correctness in other languages.

Re: Haskell is our first choice for building production soft... by Blikkentrekker on Monday January 11, 2021 @06:09AM (#25727362)
I learned both Haskell and Rust self-taught an still find the latter's type system a bit of a cage for it's lack of higher kinded types, frankness be.

I know not much of Java, but my sentiments concerning C++ are even worse.

I do not regularly program in Haskell and far more often in Rust.

Re: Haskell is our first choice for building production soft... by platinumrad on Monday January 11, 2021 @07:27AM (#25728002)
"I don't know much about this thing but I don't like it, and I know even less about this other thing and I like it even less!"

For what it's worth, C++ has HKTs in the form of template template parameters, making it possible to write, e.g., monad transformers, which cannot be done in Rust, last I checked. Now as for whether you'd actually want to do this in a production codebase...

Re: Haskell is our first choice for building production soft... by marcosdumay on Monday January 11, 2021 @09:14AM (#25729054)
Rust metadata (not just types) have an habit of getting in your way.

It is all for good reason, you can't ditch the GC and have control over the memory structure without the compiler complaining about details here and there. But fixing those strings versus slices and iterator type mistakes is really annoying.

Re: Haskell is our first choice for building production soft... by mlthoughts2018 on Monday January 11, 2021 @09:42AM (#25729393)
I find the compiler an annoyance in Haskell just as much as C++ - it just forces me to write more code (more liability) and leads to overly rigid type system designs, like modeling behavior with classes or traits/type classes. I’ve only found these ways of writing software to be universally worse than simple module-oriented programming, writing C-like code in languages like Python or Ruby and only selectively using C extensions for isolated cases where speed provably matters.

Compilers do not offer compensating benefits, like catching bugs or ensuring behavioral correctness, that justify all the extra rigidity, slowness, and especially liability of all the extra code (even in Haskell).

Re: Haskell is our first choice for building production soft... by portal_narlish on Monday January 11, 2021 @02:53PM (#25735400)
Strong point! As a non-CS engineering student learning C++ for the first time, the compiler all but turned me off from wanting to be a programmer. No one explained why the compiler was even there, it just seemed like an annoying hindrance stopping me from getting good grades on the homework.

Fast forward a decade and I'm evangelizing statically typed FP at conferences. The value of the compiler is redeemed after self-teaching and learning the "Whys".

Re: Haskell is our first choice for building production soft... by cogman10 on Monday January 11, 2021 @11:53AM (#25731644)
I run into the same thing with Java.

Code that always upsets me is something like `Map<String, Object>` where a concrete type would work so much better (and faster).

Using a statically typed language, the most important thing you can do is USE IT. Let the type system save you from problems. Encode whatever you can in the types.

Bypassing it by casting always causes headaches.

Re: Haskell is our first choice for building production soft... by slifin on Monday January 11, 2021 @06:57AM (#25727770)
"acts as an invaluable pair-programming buddy that gives instantaneous feedback during development."

This is the key bit, this is called static analysis, you don't need a type system in your language to do this, and you don't need to force doing it at compile time

Most developers appear to conflate the two, uncoupling static analysis and type systems would benefit most workflows

Re: Haskell is our first choice for building production soft... by mrkeen on Monday January 11, 2021 @07:24AM (#25727979)
> you don't need to force doing it at compile time

What assembly instructions should the compiler emit if you write sum ["foo", "bar"] ?