Suggestion: Fortran-like Keyword to Assert Function is Pure

Some examples from broadcasting:

  • In f.(u) .+ g.(v') (with u,v both length N vectors) you could perhaps do N evaluations of f, not N^2. But for something like f(x) = x + rand() this would change the answer, perhaps that’s impure for this purpose.

  • In the gradient calculation for f.(u), knowing that f does not close over other parameters would I think simplify how we handle it. Here f(x) = y[1] + x would be pure under Mason’s macro’s definition, but this needs something stronger.

Edit – it seems that Base.issingletontype(typeof(f)) is a reasonable test for the 2nd case. The 1st seems to want a weaker definition than @pure’s, it’s not the method table that’s the concern. Whether this could be inferred, I don’t know. It could also be provided either when defining or when calling the function, like @purecast f.(u) .+ g.(v').

4 Likes