Function accepting a parametric function

question
#1

Hi all,

I am trying to port some code I inherited from Julia 0.6 (via Julia 0.7) into Julia v1.1. The code below worked in v0.6, but errors in v1.1. The approach/syntax is outside of my understanding, in fact I have trouble making a minimal toy example. I looked through the manual and other packages for examples that follow this design, but I couldn’t find anything quite like it.

This code:

function estimator_convergence_order(est::DerivativeEstimator{Dim}) where Dim
  @assert 1 ≤ Dim ≤ 3
  # ... (more code branching on the value of Dim below)
end

fails when accessing Dim (first line) with : UndefVarError: Dim not defined

The module has quite a bit of code that uses this design (not having to specify the number of dimensions in the function signature, but branching internally).

I’m not sure if this is a syntax issue, or a design issue, so any help would be appreciated.

0 Likes

#2

It may be a failure somewhere else, since

struct DerivativeEstimator{Dim} end

function estimator_convergence_order(est::DerivativeEstimator{Dim}) where Dim
  @assert 1 ≤ Dim ≤ 3
  # ... (more code branching on the value of Dim below)
end

estimator_convergence_order(DerivativeEstimator{3}())

works fine in Julia 1.x.

You should work through the manual up to at least the Methods chapter.

0 Likes

#3

Thanks! I’ll build up the toy example now to find where the issue is.

0 Likes