News for hackers. Stuff that matters.
Re:Why don't more languages offer flow typing? by chriswarbo on Monday April 04, 2022 @12:17PM (#30908385)
Nobody's mentioned dependent typing yet, but languages like Idris and Agda will "narrow types based on control flow" (in fact, since they're pure-functional, control-flow is the same as data-flow). For example, zipping two vectors of the same length:

    zip: Vec n t1 -> Vec n t2 -> Vec n (t1, t2)
    zip Nil Nil = Nil
    zip (Cons x xs) (Cons y ys) = Cons (x, y) (zip xs ys)
Here the 'Vec' type has two constructors, Nil and Cons. Since their types specify the same length, the type-checker knows we can ignore the 'zip Nil Cons' or 'zip Cons Nil' cases.
Re:Why don't more languages offer flow typing? by alduin32 on Monday April 04, 2022 @03:57PM (#30911300)
This is amazing, but I don't understand the justification :

> Since their types specify the same length, the type-checker knows we can ignore the 'zip Nil Cons' or 'zip Cons Nil' cases.

Specifically, I have trouble understanding "their types specify the same length". Whose types ?

Re:Why don't more languages offer flow typing? by masklinn on Monday April 04, 2022 @04:41PM (#30911705)
The types of the vectors: the length is a generic parameter to the type. So a Vec 4 Int and a Vec 5 Int are different types.
Re:Why don't more languages offer flow typing? by alduin32 on Monday April 04, 2022 @11:43PM (#30915086)
Oh right, the output is parametrized by the input. I suppose this is what dependent types are.

That's really awesome. Thanks for the explanation.

Re:Why don't more languages offer flow typing? by masklinn on Tuesday April 05, 2022 @02:33AM (#30915921)
> Oh right, the output is parametrized by the input. I suppose this is what dependent types are.

Dependent types is really about the ability to parameterise types over values, and reason on those values-dependent types.

Re:Why don't more languages offer flow typing? by earleybird on Monday April 04, 2022 @05:07PM (#30911933)
You might read the Vector type constructor 'Vector N T' as "this is a Vector of T's of length N'.