Hacker News new | ask | show | jobs
by StefanKarpinski 3260 days ago
> Ah, I see. Yes, I was imagining something more like Numpy.

Understandable. The approach and philosophy is very different, however. Julia feels much more like dynamically typed C++ than it does like Python with heterogeneous arrays added on.

> you would have to make the "flatten" operation user-visible

This seems like it would be a method of the `convert` function. Built-in types are barely special at all in Julia, so you could – and people have [1] – make purely function analogues of any data structures you like and use all the usual operations on them. One can even allow mutation when necessary, but just make the non-mutating operations sufficiently efficient that mutation is rarely necessary.

A fair amount of mathematical code does typically work in two distinct phases:

1. construction/mutation phase – vectors and matrices are constructed and mutated to setup the problem;

2. computation phase – vectors and matrices are used in computations, typically in a purely functional manner, where each operation creates a new objects (e.g. `Z = sqrtm(2X + Y^2)`).

Unfortunately, purely functional collections don't help much with either of these phases: the first phase is inherently full of mutation and typically quite local, so the drawbacks of mutation are limited; the second phase is already inherently functional but doesn't need functional data structures. What you really need in the second phase is escape analysis that is clever enough to figure out that it can reuse temporaries.

[1] https://github.com/JuliaCollections/FunctionalCollections.jl