# Understanding 'TypeError'

**URL:** <https://discourse.julialang.org/t/understanding-typeerror/2182>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [February 20, 2017, 12:44pm UTC](https://discourse.julialang.org/t/understanding-typeerror/2182 "2017-02-20T12:44:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![leiteiro](https://avatars.discourse-cdn.com/v4/letter/l/b5e925/32.png) [@leiteiro](https://discourse.julialang.org/u/leiteiro)\
**Post date:** [February 20, 2017, 12:44pm UTC](https://discourse.julialang.org/t/understanding-typeerror/2182/1 "2017-02-20T12:44:23Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [February 20, 2017, 1:52pm UTC](https://discourse.julialang.org/t/understanding-typeerror/2182/2 "2017-02-20T13:52:29Z")

</div>

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

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

```

And your line 24 is

> [@leiteiro](#):
>
> 0::10

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

Also note that you didn’t assign to `a`.

---

<div class="post-metadata">

**Author:** ![leiteiro](https://avatars.discourse-cdn.com/v4/letter/l/b5e925/32.png) [@leiteiro](https://discourse.julialang.org/u/leiteiro)\
**Post date:** [February 20, 2017, 6:42pm UTC](https://discourse.julialang.org/t/understanding-typeerror/2182/3 "2017-02-20T18:42:53Z")

</div>

> 0::10

Embarrasing.  
I apologize.
