“So, one of the great things about Haskell actually, that is spoken about and I think it’s the sort of killer app for Haskell, is that it’s so refactorable, right? You can do a heart or lung transplant on GHC and make truly major changes and the type checker just guides you to do all the right things.”
Freely refactoring the code with worrying about unit tests, etc seems quite appealing.
To summarize the killer app for Haskell is that “it’s so refactorable”
> You can do a heart or lung transplant on GHC and make truly major changes and the type checker just guides you to do all the right things.
I thought GHC was famously a nightmare to work in?
> GHC is not exemplary of good large scale system design in a pure function language. Rather ironically, it violates the properties that draw people to functional programming in the first place: immutability, modularity, and composability
> many new features have been force-fitted into the existing code without proper redesign
> While the current design isn’t glorious, it works
I guess that's two different things. One person says "You can give GHC a heart transplant" and the other says "GHC needs a heart transplant: Here is our proposal". In fact, the very text you quote as saying GHC was famously a nightmare says:
> On the bright side, GHC is written in Haskell, and this language is particularly well suited to performing massive refactorings with confidence that nothing breaks. Thus, it should be possible to refactor the GHC library towards a more robust and versatile design
and in fact Simon Peyton Jones continued by saying exactly that:
> You can do a heart or lung transplant on GHC and make truly major changes and the type checker just guides you to do all the right things. The difficult stuff is envisioning and being very clear about what you’re trying to do. Actually doing it is often not that hard.
So the two texts and the two opinions are completely in alignment. GHC is famously bad insofar as it has a poor design. But once a better design is designed, you can give it the heart transplant it needs without excess stress.
I have no idea how the heart transplant proposed by Sylvain Henry, John Ericson and Jeffrey M. Young is going. I suppose at some point there should be something checked in and a report about how painful or painless it was (and, potentially, if it's really completely wrong, perhaps a series of bug reports in the next seven releases of GHC).
Almost all the recent work has been performed by Dominik Peteler (@mmhat) during Google summer of code, which John supervised. We've primarily been focused on landing !8341[0] which makes huge strides in Core w.r.t. modularity (see https://gitlab.haskell.org/ghc/ghc/-/issues/21872), but are on hold until schedules agree and some vacations end.
So the modularity project is far from dead. In fact Sylvain and I are planning on returning to it after we upstream the new Javascript backend (slated for 9.6, see MR!9133[1], tracking ticket[2]) hopefully this week.
PS: That patch is actually a good example of a gnarly lung transplant for GHC's Core IR (and done by a new contributor!).
I don't know. But - and this is my interpretation, not some summary of another talk - it sounds like Simon Peyton Jones, who is one of the people who are responsible for the poor state of the code, already answered that: "The difficult stuff is envisioning and being very clear about what you’re trying to do." Presumably, wherever his skills lie, they don't lie in envisioning a better state and refactoring the code towards that goal (to him, it was "difficult stuff", and left aside as he implemented changes that had a greater impact on its users). Afaik, for a long time GHC was maintained by the same two or three people so it probably shows the imprint of individual developers much more than your average compiler of similar size. Now development is much more open and this kind of technical debt is getting paid off.
We use Haskell at Bitnomial, and I can confirm that this is in fact the case. We've been able to incorporate new complex knowledge quickly in a way that most other languages would have more trouble with. Refactoring is a secret weapon for Haskell.
> You can do a heart or lung transplant on GHC and make truly major changes and the type checker just guides you to do all the right things.
This only tells that SPJ never had to work in hard realtime nor kernels.
GHC code throws and doesn't help in violating latency bounds. Not at all. For such tasks we do have much better systems, without GC.
I don't think it's a universal property of functional languages. Haskell is also strongly (excessively) typed, down to the level of modeling computation itself, and it's lazy.
See, when you are defining a Haskell program, you are conceptually creating a tree of thunks that eventually get executed by the GHC runtime. Those thunks are typed, meaning they have typed inputs and outputs, and are either side-effect-free or are defined in a context that controls their side effects (e.g. the IO monad).
So you can change the definition of types willy-nilly and either get a working compiled program or some error output that tells you exactly what is broken or doesn't make sense to GHC's model of your proposed computation. Because computation itself is typed, you have a stronger guarantee that it will work as expected when executed by the GHC runtime. Because side effects are controlled, you are forced by the type checker to handle runtime errors (or crash).
At least that's how I understand it as someone who works with gifted Haskell engineers, but exists very much on the periphery of understanding.
> Because side effects are controlled, you are forced by the type checker to handle runtime errors (or crash).
This is generally true in idiomatic Haskell code, but in fact even pure functions in Haskell can throw runtime exceptions, and you are not forced to handle these.
Bottom has to be a member of every type because functions aren't guaranteed to terminate, so there's no really any way around that within the confines of a general purpose programming language.
That admittedly doesn't entail that Haskell ought to have special functions like 'error' that invite the programmer to explicitly introduce bottom values as a mechanism of signaling errors. However, in the real world, executing any function may raise an exceptional condition at any time (e.g. an out of memory error), regardless of programming language.
More info here: https://wiki.haskell.org/Bottom As bottom is the value of a non-terminating computation and a computation of any type may fail to terminate, bottom must inhabit all types. The same goes for 'error'. Although in real world Haskell code (using GHC) you can trap error values if you really want to, so 'error' isn't in fact indistinguishable from non-termination.
A functional language is fundamentally one where the same inputs always produce the same outputs. So you can e.g. change the order of two function calls and be confident that that's not going to change the behaviour, without even running it. In a language with pervasive state mutation, essentially any change you make to the code might change what the program does, so you have to test every little thing. https://www.lihaoyi.com/post/WhatsFunctionalProgrammingAllAb...
Type systems of functional languages are generally capable of representing more. You can have the type system validate application state at compile time for you, for example.
If it compiled before and worked and your refactored version also compiles, chances are you didn't break anything.
> If it compiled before and worked and your refactored version also compiles, chances are you didn't break anything.
And I would say that if somebody never worked with Haskell (or some other language with a strong type system like Idris) they can bit fantom what is possible to encode in the type system.
One practical example: if you have a union of A|B, and you decide to add a third shape C to it, your program won't compile until logic for C is written in all the places where A and B are already being matched against. Refactoring often means changing data models, then letting the errors walk you through the actual implementation details.
Yeah that's how it's supposed to work. Historically, Haskell didn't always make incomplete patterns an error, even now the checker isn't perfect, and even if it was people can still put wildcard patterns.
With mutable state every function has an implicit dependency on other stuff. Without mutable state your function depends on its arguments, and produces only a return value. No moving parts or implicit dependencies = you can cut and paste stuff around the code base like there is no tomorrow.
Because it is more difficult to make a change that affects other code without a change in types occurring, which will make compilation fail until all affected code is updated.
In addition to the type system, I'd also add purity. If you have a function f :: a -> b, there is literally no way for f to read anything besides a, or affect anything besides returning b (aside from unsafePerformIO, which you can ban from your code.) so if you want to refactor f, you know exactly from the call site everything that needs to be updated.
all state is factored, so it can easily be refactored.
It’s mostly the type system. Ocaml is the same. Static typing, type inference and the easiness of introducing complex types really help when it comes to fitting the code together. Beginners tend to think that "if it compiles it works" and it feels that way sometimes but you lose the hubris once you are bitten by a bug complicated enough to pass though.
Perhaps it is easier because Peyton Jones is a world class expert in Haskell and have 30 years experience refactoring it?
In my experience the ease of refactoring is more depending on the quality of the code you are refactoring than the language. That said, a strong type system helps avoiding stupid mistakes and Haskell have a very strong type system.
> JB: So is it refreshing to to work on an implementation of a language from scratch after having worked on this 20-30 years old codebase in GHC and all this big beast where you can’t just redo everything from scratch?
> SPJ: It’s a very different prospectus because in this case Verse is a pretty well-formed beast in Tim’s head. If we want to do something different we’re going to have to persuade him but I’m fine with that, right? But the dynamic is that he’s a sort of technical lead on the project – which is very unusual for the CEO of a multibillion dollar company and actually quite rewarding.
Any tips on other professors like SPJ? He seems like a super human even after the 10 years Ive followed him. Never angry, always happy, always engaged, always teaching things with depth, not dumbing things down to make it easier, not pandering…
Most academics don’t have as many interviews and talks uploaded with them as SPJ but check out Stephanie Weirich’s Strange Loop talk[1] and interview on Corecursive.[2]
Why is Haskell, a comparatively obscure language (to Python, C++, etc.), so popular with topics in the orbit of "web3" (blockchain, crypto, metaverse, etc.)?
Part of my confusion is also the social/community aspect, especially with Haskell hackers' frequent and negative attitude toward the enterprise, like Stephen Diehl who has become a sort of spokesperson for the "web3 is a farce (and worse)" narrative. It seems like such a stark juxtaposition, especially with SPJ and Lennart Augustsson, two research giants of the community, taking part in it in a serious capacity.
(To be abundantly clear and uncontroversial, as it pertains to this comment, I'm not interested in discussing "is web3/metaverse {good,bad}", but rather in discussing the purely functional programming community-of-community's interests or anti-interests in it.)
I reckon SPJ is sufficiently "researchy" that it doesn't really matter how it's applied, it's the research that matters. Also, he seems perpetually delighted that he gets to do what he does, and is paid to do so.
OCaml also has some of that, with Tezos, and Rust with Solana. I think it's because functional languages are thought as producing safer code, which is important in this industry.
First, I'm not sure if Haskell is that popular in that space. But I'd say there's a combination of factors.
Python/C++ come with their issues and when starting a project from scratch (e.g. a blockchain), there's more flexibility in the choice of language. In the blockchain field, throwing buzzwords has proven useful to gather money and make some projects stand out (functional programming, formal verification...). Also academics love these language, so starting a project in Haskell/OCaml can get you contributions from academia, possibly some big names joining your team. And of course, strongly typed languages with a clean semantics give you more safety which is important in some fields.
Functional programming lends itself well to finance through correctness and also the fact everything you do is basically data in -> data out. Versus other domains where using stateful objects to model things is easier.
Mainly because using monadic I/O trivially encourages you to write pure (deterministic) code for most of your programs, which makes it easy to write tests for them. Besides that, it's easy to write great libraries, which then makes the language very expressive. The downside is that the cognitive load for using it can be very high, but looking at C++ it seems clear that high cognitive loads are a feature across the industry, and here to stay.
I think I operate in those orbits, but I haven't come across much Haskell (plenty of TS, Golang, Rust). Where Haskell has cropped up it was typically in the context of "we want to prove this code is correct" (plausibly important if money is being transacted), plus a bit of "we like Haskell so we used it".
“So, one of the great things about Haskell actually, that is spoken about and I think it’s the sort of killer app for Haskell, is that it’s so refactorable, right? You can do a heart or lung transplant on GHC and make truly major changes and the type checker just guides you to do all the right things.”
Freely refactoring the code with worrying about unit tests, etc seems quite appealing.
To summarize the killer app for Haskell is that “it’s so refactorable”