176 points · by xiaodai · 6y ago · 191 comments
Idris as a descendant of Haskell I have no argument with.
Rust however, is more correctly viewed as (primarily) a descendant of ML languages, which all possess the properties the articles lists as derived from Haskell. Perhaps it is more correct to call Haskell and Rust cousins, both deriving from the same lineage of languages.
I would also not call Julia a child of Haskell. As it is more correctly viewed as an interpretation of Matlab as a Lisp, I'd therefore call Julia a descendant of Lisp. That Haskell single handedly popularized the utility of category theory in computing and that a category theory library is written in Julia does not make Julia a child of Haskell any more than it would have made Ocaml a child of Haskell (there used to be a category theory library written in Ocaml).
The popularization of functional programming, Domain specific languages as algebras, reactive (not FRP), property based testing, parser combinators, model view update for UIs, design principles secretly based on monads are all but a few of the ways Haskell has influenced programming. Which is the core point of the essay and with which I am in full agreement.
This thread somewhat has the air of an eulogy but it goes without saying that just because something is not the most popular in fashion does not mean it is dying.
I would be interested to learn of features in Rust that came from ML and that aren’t features of Haskell - not counting strictness :-) I can think of a non-example: one of ML's distinguishing features is its functional (in the FP sense) module system; Haskell and Rust have more conventional module systems.
You could maybe argue that a Rust enum definition is more like an ML type definition than a Haskell data definition because the constructor parameters are tuples rather than curried, but it isn’t clear to me whether this is actual influence from ML, or Rust aiming to be more C-ish.
As I understand the history of algebraic data types and pattern matching, they first appeared in Hope, and from there they were added to ML, and on the separate branch of lazy functional languages they were inherited by Hope’s successors Miranda, Orwell, and Haskell.
> Rust that came from ML and that aren’t features of Haskell
> As I understand the history of algebraic data types and pattern matching, they first appeared in Hope, and from there they were added to ML, and later adopted by Hope’s successors
They appeared first in a practical form in Hope but I'm taken to understand that these ideas could already be found in Programs and their Proofs: An Algebraic Approach and the core ideas are clearly present in this 1968 paper by Burstall: http://www.cse.chalmers.se/edu/year/2010/course/DAT140_Types...
Creators of HOPE, VAX ML (which also had limited patterns and case analysis) and LCF/ML all influenced each other and played prominent roles in the design Standard ML, which would in turn strongly influence future functional languages, including Haskell and Ocaml. It's tricky to untangle the history but I don't think it's controversial to say SML popularized functional programming as prototypically understood today (before Haskell evangelized it further).
> Rust’s two most prominent type system features are lifetimes and traits
Other than the initial prototype being written in Ocaml, I'd say Rust's pragmatic feel: eager evaluation, immutability by default but a hatch to mutability and the implementation of the features listed in the posted article all make it feel more like an ML. I agree, though, that this is a subjective take.
Though the original Rust compiler was written in OCaml, so depending on your viewpoint it could also be its child. I'm not sure if Rust lifted any features or syntax from OCaml specifically. I think the "O" in OCaml was not influential ...
----
edit: I found a list of influences, and it does credit Haskell with typeclasses, but SML/OCaml and C++ are credited first:
https://doc.rust-lang.org/reference/influences.html
I always thought of Rust as a mashup of OCaml and C++, but Haskell is in there too.
Some History of Functional Programming Languages (David Turner) https://www.cs.kent.ac.uk/people/staff/dat/tfp12/tfp12.pdf
Miranda was open sourced earlier this year! I remember downloading the tarball and looking at its source code.
https://old.reddit.com/r/programming/comments/fbtmar/miranda...
https://www.cs.kent.ac.uk/people/staff/dat/miranda/
https://www.cs.kent.ac.uk/people/staff/dat/miranda/downloads...
Why would that be more correct? Would Rust have these features if they were not popularized by Haskell? I don't know the answer, but it seems like discussing which language some feature was taken, when more than one contemporary language has it, is a kind of meaningless pedantry.
Though I'm not really sure that it matters.
Hmm...
> When I first started using Rust, I really missed monads.
Option and Result are Monads. Surely he misses do-notation.
> This all being said, I think it is worth looking at the features that are prominent in Haskell that ended up going to Rust ...[list of features that Rust got from SML/ocaml]
Here are the officially stated Rust influences: https://doc.rust-lang.org/reference/influences.html
To say that Rust is a child of Haskell is really overstating the case.
You can find monads everywhere if you look hard enough. But Haskell actually lets you use those discoveries for massive code reuse, while Rust forces you to write stuff like Result::and_then and Result::map over and over again.
> To say that Rust is a child of Haskell is really overstating the case.
Right, most of these are common influences. I'd say Rust's main contributions are (a) the ownership system, and (b) painting a thin coat of C++ syntax over ML features to make them more palatable, and neither of these seem all that inspired by Haskell.
(Of course you still want some form of nicer notation than the raw one, but that's beside the point.)
Little abbreviations might be widely used, but when people talk about code reuse I'm hoping to hear about ways to share larger chunks of code, not having shorter idioms.
In Rust, the functions Result::and_then, Result::map, Option::and_then, Option::map, etc. are pretty much all saying the exact same thing, but they need to be reimplemented over and over again. With Haskell, Result and Option (and [], QuickCheck.Gen, Data.Binary.Get, etc.) just need to implement return and (>>=), and they get a ridiculous amount of useful functions for free (mapM_, foldM_, forever, ap, etc.). That's a "large chunk of code" saved in my opinion.
https://hackage.haskell.org/package/base-4.14.0.0/docs/Contr...
And, of course, they also get some very nice sugar in the form of do notation.
The feature of Haskell that lets you avoid writing 'and_then" over and over is do-notation.
Rust does not have higher kinded types, which are required to have abstractions like the Functor and Monad type classes in Haskell.
Option and Result are monadic, but they must implement their own, separate methods and can not share a common interface. Which takes away a lot of expressive power.
There is a accepted proposal for something similar, known as GAT [1] (generic associated types). But that is blocked on other work and might never actually be implemented.
In a theoretical sense, sure, but in a practical sense, my understanding is that GATs already exist in chalk, and so it's still a matter of putting in the work, not a question of "is this possible or not."
You would know better of course, but it was my impression that there is no firm commitment to stabilizing GAT, even once the compiler fully switches to Chalk, due the potential disruptiveness and complication of the language.
(For those unaware: Chalk is a rewrite of the trait logic in rustc, based on logic programming [1] )
With the caveat that some languages support an encoding of HKTs. You can encode HKTs in OCaml, Kotlin, or TypeScript for example, and there are FP libraries taking advantage of that. I believe the encoding was inspired by this paper:
https://www.cl.cam.ac.uk/~jdy22/papers/lightweight-higher-ki...
It kind of sucks, but it does let you work with a Monad type class, and it's better than not doing it at all.
I'm not sure if such an encoding is possible in Rust. I've been told that F# has a hard time with it, not sure why (possibly because of reified generics). In TypeScript and Kotlin it works because the runtime and the type systems are relaxed and you can just force downcasts if you're in trouble.
Just to add some tangential color here: even if you don't intend to use this encoding in production, it can be a fruitful intermediate step in refactoring! I just recently ran into a situation in Java where I had some tightly-coupled concerns for which HKTs were the obvious way out. Since Java doesn't have HKTs, I applied the HKT encoding to get the hard part out of the way, and then discovered a simplification that brought me back into the realm of idiomatic Java. I would not have found the final solution had I not pathed through HKTs -- I actually thought it would be impossible to do this decoupling properly at first!
More color: the paper itself describes this approach as an application of defunctionalization. I use defunctionalization a lot, too, to write an obvious recursive solution and then mechanically transform it into an iterative one. So it's nice to know how to apply it at the type level, too ;)
Well, functions and lists are also monads. I guess what the author means is that the language recognises the similarity of those disparate structures.
The article really rubbed me the wrong way with this tidbit
> (we don’t talk about Go…)
So since the author is speaking of "premier system’s language" we choose to ignore the world's premier cloud language? Interesting.
EDIT: also, strictly speaking, Rust doesn't use Hindley-Milner, and we don't have parametric polymorphism.
struct Person<T> {
age: T,
}
Is parametric polymorphism and valid Rust.> However, in 2020, the premier system’s language is surely Rust.
Yesterday I was speaking with a friend who runs a small company doing contracted embedded programming (the embedded OS is often Linux but often not) and he'd never even heard of Rust. Maybe it's a little lower level than what's meant by "systems" here but still, the article's statement is just delusional.
I can go to Green Hills and get a contract that guarantees their compiler will be available and supported for my target platform for the next 10+ years. Rust is still a moving target with a single implementation, and no (present) way to get the guarantees needed for the embedded domains I've been involved in. I'd like to see Rust experimented with there, but it won't be the "go to" language for quite some time.
It's just that in Haskell you have to write fewer tests to be sure you did it right, because for many kinds of mistakes you could have made, the compiler can yell at you.
The other advantage of nicer types is that they serve as part of the documentation. Exactly because the types can constraint the behaviour of implementations more than in Go. So the reader can make more valid assumptions from the type alone.
Hoogle uses those types to give you a truly extra-ordinary way to search the Haskell libraries via types. That approach would be almost useless in Go, and you have to fall back to searching via keywords etc only.
When you write code that operates on something like a monad, without caring about what the monad is, you want code that has a type like <T1>[<T2>]. In haskell syntax, it's m a. <T1> (or m) in this case is a type that takes another type as an argument to complete a concrete type. AFAIK, rust doesn't have type variables that take type variables (or types) as arguments like that.
That's part of it. Option and Result are concrete instances of Monads. He misses the Monad abstraction.
> Option and Result are Monads. Surely he misses do-notation.
Surely you are joking if you are trying to say someone writing haskell would say rust has monads in any practical sense. Sure, all languages have/can have A (or two) monad.
Soon you can even deploy haskell web apps in 15 seconds: https://twitter.com/larsparsfromage/status/13066539171876495...
Growing between 5% and 10% weekly. Many new people are starting their journey into haskell with IHP :-) While the community might be changing, it's definitly not dying.
E.g. on Sep 1. we had 870 GitHub stars and 321 Twitter Followers. Now (23 Sep) we're at 970 GitHub stars and 487 followers.
IHP has been launched around 3 months ago. So we're measuring it since then.
I am a huge Haskell fan though. The 'problem' with Haskell is that, because of its roots in academic research the language will not chase success at any price (read hacks); and tends to eventually find solutions to its problems even if it means not being popular for a long time. I like that. Watch out for stuff like linear types[1] coming to GHC soon.
That's the PR line, but only describes about 5% of the problem with haskell.
But haskell's not relatively unpopular because it was late to add things like linear types. It's relatively unpopular because it doesn't care much about user experience.
Consider: it's getting linear types before an efficient string type in `base`. The first goal of this language is not good engineering practices and getting things right. The first goal of this language is "cool type stuff", with good engineering maybe goal 10 or something (is O(n^2) `nub` ever going to be deprecated I wonder?). And that's fine, we need a language for cool type stuff, let's just be honest about it.
Context: I've been Haskelling for 5 years, I've written a fair amount of FOSS in it, and it's my favorite language. I just want to help spread an honest impression of it.
IMO Haskell remains as the go-to language for teaching functional programming and for experimenting with PL concepts. Long may it remain.
I like using Haskell for writing compilers, but I would probably not like to use it for numerics code. While I could replace Haskell with Idris, I'm still a bit lukewarm on the cost-benefit of heavy use of dependent types for many programs (although Idris has other nice advantages unrelated to the type system).
Elm is a more special-purpose child, but seems to have had an impact on JS practices, as a 'gateway' to functional programming. PureScript is also interesting but hasn't had as big an effect.
I agree with the article that Idris is really nice; although I'd lump Agda in with it as a dependently-typed child of Haskell, and contrast them both against Coq (rather than lumping Agda and Coq together).
I've also played around with Curry and found it quite interesting (functional logic programming), although it's essentially a research language.
I personally believe, agda is an excellent programming language. It's stdlib is good, concepts and construct are very well-thought out, it's very safe and works surprisingly well. I've been programming in agda for years and almost never had issue implementing anything even though it's not Turing complete. Using sized types you can prove most sane things to terminate anyway. And if you really need infinite loops (say, you're implementing an interpreter of a Turing complete language) then you have many options: (1) disable termination checking for a single function (2) use Haskell to implement a single function (3) use Rust, C, C++ etc to implement a function then with GHC ffi link it to agda.
Maybe I'm just being near sighted, but I'm really surprised more people don't use Agda or Idris in production. The number of times the type system saved my ass is uncountable. You can literally write unittests in your type system it fekkin runs your custom unittests while type checking. How is this not revolutionary? I don't understand.
My main gripe with dependently-typed languages is the amount of wheel-reinventing that's involved; e.g. I might have crafted a "ListOfIncreasing comparisonFunction" type, which is perfectly suited to the problem I need to solve, but then I find myself implementing a map function, a filter function, an append function, a length function, etc. Then I find myself needing a "length of appending commutes" lemma, and an "empty is left identity of append" lemma, and an "empty is right identity of append" lemma, and so on.
It's really nice when it works, as a nice self-contained little module; but any more can get exhausting. I haven't tried integrating Agda with Haskell, but that sounds like a nice tradeoff: do all of the "boilerplate" in Haskell (string plumbing, etc.) to get a "Maybe InputsForMyAgda" value, pass it into whatever tricky algorithm we've managed to implement thanks to Agda keeping us in check, then send the result back into Haskell for throwing into whatever external monstrosity we're interfacing with.
I don't know why you had problem with compiling... All you have to do is run `agda --compile src/Main.agda` and it just works...
> My main gripe with dependently-typed languages is the amount of wheel-reinventing that's involved; e.g. I might have crafted a "ListOfIncreasing comparisonFunction" type, which is perfectly suited to the problem I need to solve, but then I find myself implementing a map function, a filter function, an append function, a length function, etc. Then I find myself needing a "length of appending commutes" lemma, and an "empty is left identity of append" lemma, and an "empty is right identity of append" lemma, and so on.
This is true to some extent, but this has nothing to do with Agda. If you're working in an extremely strict type system like agda's where all types need to be provably constructable, you cannot just start coding. You need to have a good idea what your program will look like. E.g. if you're writing a parser (as I often do because writing parsers in agda is such fun) you need to know some mathematical structure behind parsers.
Take a look at this page: https://agda.readthedocs.io/en/v2.6.1.1/language/sized-types...
Here they build Kleene star, which expresses infinite computation. However, you need to construct it in a (coinductive) way such that it doesn't infinitely loop. You cannot just code something like this. In that page they use a paper to base their functions. You need to know the math behind this to have an idea what will work. But you also absolutely don't need to be a mathematician either. And if you have no clue where to start, having multiple iterations of your program usually results in success. E.g. sometimes I start coding agda, then realize my types aren't good enough, restart, rinse and repeat. In my experience Haskell is much better for programs like this. Once you write your program in Haskell and have an idea where things are going, start formalizing some functions in agda, and then try to rewrite everything in agda. Writing programs in agda doesn't mean it's correct, of course, your business logic can still be wrong. The power of agda that comes from dependent typing, is that you can encode tests and proofs of your invariants into the type system. This means if you really want X to be always correct you can prove X or of it's not easy, you can write a whole bunch of unittests that'll be checked at typecheck time.
Regarding FFI, it's actually very easy, read here: https://agda.readthedocs.io/en/v2.6.1.1/language/foreign-fun...
You can add arbitrary haskell code in your agda programs. If you compile with `agda --no-main` agda doesn't call GHC so you can manually call GHC to link your program. This means you can do everything you can do with GHC to your compiled Haskell code in MAlonzo/
The benefits look really promising e.g. proving forall x -> f x == g x -> f == g. I really want to use this theorem in some of my agda projects, but I never needed it desperately enough that I had to drop everything and do this. My usual workaround is implement slowButEasyToUnderstand function. Do a whole bunch of proofs with slowButEasyToUnderstand. Implement fastButComplicated function. Prove forall x slowButEasyToUnderstand x == fastButComplicated x
I think one immediate application I can think of with cubical is, you can implement mergeSort : List X -> List X and then pass this around everywhere. You don't need a Sorter record or whatever since when you implement quickSort, you will be able to prove quickSort == mergeSort, so everything will typecheck. I don't know which will end up getting compiled though.
When I learned those, Haskell was still Miranda.
I really don't know why people think Haskell is the pinnacle of everything in PL design.
Haskell ticks all these boxes.
SML has most of those things, except the last: it was effectively frozen in 2001. This is discussed in section 9.3 of the HOPL IV History of Standard ML https://dl.acm.org/doi/10.1145/3386336
OCaml lacks a standard and multiple implementations, and seems to me to be doing better than SML in the other areas.
IMHO it is the first successfully implemented research language, though. I think that Haskell is the first language that, at the same time, had substantial commercial and research applications[1]. As such, it showed that the CS of PL is indeed of practical relevance.
Rust on the other hand, mostly applies this scientific research. And successfully so. Hence I call it the "engineering" part.
[1] To a certain degree this is also true for Lisp and SML, of course. But I think SML fell out of fashion quite quickly both in academia and industry. Lisp is, well, lisp. People that start using it seldom search for another language afterwards.
Could you please elaborate on that? Is it related to the new features, like lambdas, pattern matching with switch and so on?
Wut? Rust doesn't have the purity and the capability to isolate side-effects that Haskell has. Rust is popular because of its ownership model that got into the mainstream. We still don't know what are the costs of it.
The only similarity between them is that both are statically typed, expression based languages (ex. Scala, Ruby, Wolfram, LISP) and moved the task of proving stuff from analysis tools to the programmer. But that doesn't mean that Haskell "is the science" behind anything. For what it's worth, Rust is closer to the ML (OCaml) family than Haskell, focusing on performance rather than purity. Though that is also debatable since it doesn't feature a GC and comes with zero-cost abstractions.
Rust has its very own merits. I'm eager to see how it will evolve and what hidden costs will be uncovered.
Sounds interesting, do you have some links on this topic?
For me, Haskell is on the list of languages (right next to Smalltalk and Forth) that I would like to learn in the future just to experience problem solving from that vantage point, but it's taken me so long to work through SICP that I wonder if I have the time to meaningfully experience all these languages.
I have fond memory of first working through SICP in my teens. But having recently revisited the book, I realised it's mostly nostalgia.
There are better books about programming than SICP nowadays.
> What books would you recommend instead?
'Think Python' is a good introduction to programming in general. https://greenteapress.com/wp/think-python-2e/
'How To Design Programs' is another good introduction. https://htdp.org/2020-8-1/Book/part_preface.html
For functional programming in general, Okasaki's 'Purely Functional Datastructures' is a real treat.
Paul Graham's 'On Lisp' is worth reading. It's a bit on the pragmatic side. http://www.paulgraham.com/onlisp.html
Above all of them, the best book in general is 'The Pleasures of Counting'.
I think rust got this right, rustup and cargo are great tools that are easy to install and work with.
Cabal has fixed the problems from a few years ago, and Nix is a nice ecosystem to plug into, but these can get in the way at the beginning, at a point where the goal is to "create my first project, write my first program, build it, test it, run it".
(Then again, maybe you do have multiple examples and/or have strong evidence this system was indeed "Haskell done right", which is why I'm asking).
Haskell is surprisingly well suited for back-end services (e.g REST). Warp (an HTTP server), Servant (a way to define your backend API), and Mio [1] (the Haskell network IO implementation) are amazingly performant and scalable.
Of course, that does not prevent you from messing up on the business logic level. I suspect that they lacked awareness of performance implications of their choices, this is not something Haskell will save you from. On the contrary, parts of the Haskell community do tend to go to over-abstraction, and I believe this does have a negative effect on people writing production software.
- XMonad
- Pandoc
- Shellcheck
Everything else is just tools for using Haskell (Cabal etc.).
Seriously, compare:
- Haskell https://github.com/search?l=&o=desc&q=stars%3A%3E1000+langua...
- Rust https://github.com/search?l=&o=desc&q=stars%3A%3E1000+langua...
- Dart https://github.com/search?l=&o=desc&q=stars%3A%3E1000+langua...
Haskell has been around for a long time. It's not just "avoiding success at all costs," it's a nothing. It inspired good features like Option and Maybe in other languages, but it itself is on the same scale as Dart.
The first one that comes to mind is pattern matching. All your ML derivatives have had it for years, and it's an extremely powerful concept. Unfortunately, most people (myself included) had never heard of it until it hit more main stream languages like Rust and C#. Streams and the more wide spread use of anonymous functions is another great example of functional concepts making imperative languages much more expressive and powerful.
I don't like writing in pure functional languages very much, but I do enjoy a lot of the power the have and how we can make these concepts more accessible to traditional imperative languages.
I just have one thing to say.
In the real world (i.e., unlike in a tree), children have multiple parents.
I use Python / numpy heavily, and the giant hole numpy opens in my type annotations causes me grief daily. If there's something better out there, I want to try it, but it has to work. It has to work not just in the "I'm putting together a journal article and I need it to run" sense, but in the "I'm building a system that crunches some heavy engineering numbers all the time, and customers expect consistent results" sense. Can Julia be trusted?
The "time to first plot" (a consequence of the aggressive JIT that compiles large programs with heavy optimizations, as Julia doesn't have an interpreter outside of the debugger) still exists, but it is also improving at a fast rate.
[1] https://julialang.org/blog/2020/05/rr/
[2] https://juliacomputing.com/case-studies/
[3] https://github.com/JuliaPlots/Plots.jl/issues/2838#issuecomm...
JuliaCon2020: Julia Is Production Ready - https://bkamins.github.io/julialang/2020/08/07/production-re...
Discussion: https://news.ycombinator.com/item?id=24082281
There are comments suggesting that Julia is plenty capable, with libraries covering equivalent (or more) features provided by Python libraries like NumPy. YMMV.
>"The type system in Rust is obviously very influenced by the type system of Haskell, but they also implemented “ownership” which allows for the killer feature garbage-collection free automatic memory management."
I always assumed that garbage collection was simply a convenience offered by a particular language.
I was also under the impression that memory leaks were the class of problems that were addressed by garbage collection and that memory safety was a class of problems that was concerned with things like buffer overflows and corruption and addressed by runtime checks.
However after reading I feel like I have failed to understand the role of garbage collection in enforcing memory safety. Is memory management and memory safety not so cleanly divided?
Could someone explain or point me to a good resource for understanding how garbage collection is used to enforce memory safety?
- use after free
- memory leaks (failing to free)
- concurrent and uncontrolled access from multiple threads (race conditions)
Garbage collection helps with the first two. The system will not free memory until it is certain (by whatever method is being used) that the memory is no longer in use. But this comes with a run-time cost. Rust's innovation here is a more reliable way of tracking memory usage statically, and removes some of the run-time cost. Paired with its ownership/borrow mechanisms it also works to solve the third issue, which GC doesn't deal with at all.
Does that make sense?
I use PureScript everyday, and I love it. It's nearly identical to Haskell, with a few small changes that can be described on about a page
It's a fun language, and if you play with it and its ecosystem, it might give you ideas to import in your own environment.
Pick up a good book, and learn it, because it's fun. And no, you're not too dumb to learn it. Java and its ecosystem can be more complicated IMO, you don't realize it because you've put years in learning it.
Advice gratefully received!
An early version of Perl 6 was written in Haskell, which led to further Haskell influence on the language.