Understanding 'TypeError'

Please consider the module below. After having defined a function E
the following lines work as expected:

Eseq = Task(E)
for _ in 0:10
    a = consume(Eseq)
    println(a," ",typeof(a))

However wrapping these lines in a function leads to a ‘TypeError’.
Why? How can I avoid this error?

module A
function E()
    D = Dict{Int, BigInt}(0=>1, -1=>0)
    i = k = 0; s = 1
    while true
        E = 0; D[k + s] = 0; s = -s
        for j in 0:i
            E += D[k]; D[k] = E; k += s
        end
        produce(E)
        i += 1
    end
end
# --- works
Eseq = Task(E)
for _ in 0:10
    a = consume(Eseq)
    println(a," ",typeof(a))
end
# --- the same wrapped in a function
# --- does not work: TypeError  
function test()
    Eseq = Task(E)
    for _ in 0::10
        consume(Eseq)
        println(a," ",typeof(a))
    end
end
test()
end

When asking questions, please post the actual error instead of trying to summarize it.
Your function version is very different from the global one. The error says

ERROR: TypeError: typeassert: expected Type, got Int64
Stacktrace:
 [1] test() at ./REPL[0]:24

And your line 24 is

So you wrote a type assertion instead of a range as the error message suggested.

Also note that you didn’t assign to a.

1 Like

0::10

Embarrasing.
I apologize.