If it were possible to give functions types in Julia, it would ease the implementation of operational calculus in the language.
I’m thinking about ways to implement differential operators in julia, so that it would be possible to write something like the following:
□ = (∇ - δₜ)
Where ∇
, and δₜ
are functions with methods that accept tuples of the same type signature, modified by the -
operator to give a new function □
as an output
By being able to give functions a type, like
abstract function LinearOperator(::FunctionSpace) <: Function end
function ∇(A::FunctionSpace) <: LinearOperator
~some code~
end
function δₜ(A::FunctionSpace) <: LinearOperator
~some code~
end
It would be possible to overload the -
operator and other operators to give sensible functions as the output, with some special syntax to let the compiler know where in the syntax tree each atomic function should be evaluated, perhaps like
Base.*(f::LinearOperator, g::LinearOperator) = f(g(|>))
Base.-(f::LinearOperator, g::LinearOperator) = f(|>) - g(|>)
function Base.^(f::LinearOperator, n::Int)
out = (|>)
for i in 1:n
out = f*out
end
return out
end
Is this feasable? Already possible with different syntax?
Thanks for reading, I’d love to hear some thoughts on this