Wednesday, June 24, 2020

Haskell gets Linearity

The patch is merged into the main branch of the compiler.

In Linear Haskell a function may and must use its input exactly once. In regular Haskell this multiplicity is any.

Linear typing is not new. The Idris programming language recently reached version 2. The main advancement in it is its "quantitative" typing, which allows to declare and track such multiplicities. One of the allowed multiplicity is 1, that corresponds to linear typing. Thus Idris has already implemented something more general than what Linear Haskell is. But Idris is not yet ready for industrial adoption. Haskell is. Haskell is a mature, industry-strong language. Among these : the best high level one. Hence this new feature may be important.

What practical use Linear Haskell gives us? In-place rewriting for fast algorithms. Safer usage protocols, for example : checking that a file is opened before use and closed after use and not used after close. All these are possible already in regular Haskell, but linear typing makes it simpler, easier, safer.
Of course regular Haskell as we know and use it now is not replaced, Linear Haskell is only an additional capability. And there is some work being done on multiplicity polymorphism, which would allow us to write functions that can be both regular and linear.

Haskell's linearity is different from "uniqueness" typing. An object of a unique type is guaranteed to have only 1 reference to it. Thus a function recieving a unique input can memory-safely interect with it freely. This is an intuitive idea that was followed by many programming languages, including Rust. But in Linear Haskell the linearity is a property of not things, but their usages - of the functions. In Linear Haskell those are the functions that are either linear or not. Functions do not get any guarantee, but they are the ones that offer guarantee - that they use their input exactly once. In Haskell the other kind of linearity can be restored via continuations.

Haskell's linearity corresponds to linear logic. By this design Haskell yet again shows its attraction towards math. This attraction towards math is in my opinion one important cause that made Haskell the incredible success that it is, and my guess is that this linearity design will be yet an other such good decision. The Idris language also made the change from uniqueness typing to linear functions from version 1 to version 2. [This does not necessarily imply that Rust's design is bad for itself, as Rust, being a low level language, is very different.]

I guess linear typing, but rather the more general quantitative typing will be a stepping stone for dependent typing, which Haskell is heading towards. Richard Eisenberg, who is kinda the main driver of dependent typing in Haskell, already said that they are looking to learn from how Idris 2 fused these 2 capabilities.

Of course this initial implementation of Linear Haskell is poor yet, both in reliability and completeness.

If you want to dive deeper in the topic : here are some links :
  1. Simon Peyton Jones - Linear Haskell: practical linearity in a higher-order polymorphic language
  2. The "paper

Friday, August 9, 2019

Arend

As a programming language enthusiast, continuously following the news in this topic : i thought i would know about any ongoing serious project of good programming language development. And sneaky JetBrains proved me wrong. All from nowhere they suddenly announce Arend 1. Arend seems to me to be a very professionally designed programming language. With very modern type system ["homotopy"]. To give you some reference : not even F* or Idris 2 are going to support homotopy type theory, at least according to my poor knowledge. The closest competitor of Arend is Microsoft's Lean and Agda. Being JetBrains we expect good IDE support for it. And we would be right, as the IDE already now, at the start is perhaps the best among well designed programming languages. Too fantastic to be true? Yes. It has a tiny deficiency : it is not designed to create executables, one can not execute Arend programs. It is only for modelling and verification. Yet. But i am still very happy about this development, as i am very optimistic that executability will come to Arend over time and i interpret this development as one more stepping stone towards modern programming. With this JetBrains is only the second firm to have created a professionally designed programming language with powerful type system, Microsoft being the first perhaps with F* and Lean.

Monday, May 20, 2019

Guix 1 released

Guix 1 released.
Guix is the other functional package manager and operating system distribution, beside the more popular Nix.


Thursday, March 7, 2019

maybe a solution of boolean blindness

the Maybe type can sometimes solve the boolean blindness problem better then a renamed Bool datatype