4 ms·
Agreed. (Though I wouldn't exactly call Haskell a 'systems programming language'. At least not in the sense the article uses it.) Yes, linear / affine types
by eru 3y ago
Agreed. (Though I wouldn't exactly call Haskell a 'systems programming language'. At least not in the sense the article uses it.)
Yes, linear / affine types and uniqueness types can give you a lot of control over resources, while also allowing you to preserve functional semantics.
I would like to see a version of Haskell that doesn't just track IO, but also track totality. Ie unless your function is annotated with a special tag, it has to be guaranteed to return a value in finite time, ie it has to be total. If you tag it with eg 'Partial', you can rely on laziness.
That's very similar to how functions in Haskell can't do any IO, unless they are tagged with 'IO'.
(I know that Haskell doesn't see 'IO' as a tag or annotation. But it behaves like one in the sense I am using here.)
- Y_Y 3y agoAlthough I complain about them in a sibling comment, Agda and Idris do meet the criterion of "Haskell-like with totality checking".
- skybrian 3y ago“Finite time” isn’t much of a guarantee. A million years is finite. Totality checking is useful in language for doing proofs, where you need a guarantee that a function always returns a value even though you never run it. In languages for doing practical calculations, a progress dialog and a cancel button are more useful than a totality guarantee. It should be easier to make complex, long-running calculations safely cancellable. (Still true with laziness, though it changes a bit. At some point you will ask for a value to be calculated.)
- Nevermark 3y agoTotality guarantees won't ensure a timely response. But they ensure that a function that should always return a value will always return a value. I.e. they eliminate one source of bugs. So a default constraint on functions to be total, would be sensible and helpful. To be able to do the opposite, constrain a function or continuation to never terminate (outside of program termination), would be useful too. Albeit in much fewer contexts. Any constraint that forces implementations to match respective design intentions is good.
- skybrian 3y agoTo put it a different way, a totality guarantee ensures that a function will always return a value in theory, but not in practice. To get the theoretical guarantee, you need to eliminate all possible runtime errors, including things like divide-by-zero errors. It’s kind of pain when you’re not making a theoretical argument. You might still want to eliminate all divide by zero errors. Satisfying the compiler of this using a machine-checked proof might be more trouble than it’s worth, though. It might require you to use a language whose types support proofs.
- eru 3y agoYou don't need to eliminate all possible runtime errors. You just need to make sure they are handled and accounted for. That can take the form of something like `try_divide` that returns a `Maybe` that you need to pattern match on. Or it can take the form of trust-me-bro via the equivalant of UnsafePerformIO, where you know that something is safe and you want to let the compiler know, but you can't prove it to the compiler. You can also deal with errors by returning an `Either`. That doesn't mess with any totality guarantees.
- skybrian 3y agoYou're talking about error handling in practical programs. When I started out writing "theoretical guarantee," I meant in a proof, written in a proof language. Reporting an error to a function's caller isn't really a thing in a proof. A function proves that if any input exists, its result exists. Returning an error means "an error might exist." We don't want to return that, we want to eliminate the error from our proof, so that it proves that the result exists for any input. Returning an 'Ether' type might be useful in a proof, but a 'Maybe' type seems dubious. We already assume that 'None' exists, so proving that 'None' might exist is useless. We don't have the same concerns in proofs and practical programs.
- marcosdumay 3y ago> Though I wouldn't exactly call Haskell a 'systems programming language'. At least not in the sense the article uses it. I don't disagree, but... Except for excutable sizes and maybe unpredictable performance (performance unpredictability on Haskell has the same shape of UB on C, in that it creeps in, but it's way easier to keep away), there's actually no feature missing. You can argue for C-like speed (instead of Java-like), but the stuff on the article doesn't have it either.
- eru 3y ago'Systems programming language' is a bit of an overloaded term at best. I was purely going by the (implied) usage in the article. People have written kernels and unikernels in Haskell. So in that sense it's definitely a systems programming language.