Invalid redefinition when redefining an identical parameterized type

149 views
Skip to first unread message

Kristoffer Carlsson

unread,
Feb 11, 2016, 12:10:17 PM2/11/16
to julia-users
I have a file that defines a type and a few functions. Sometimes I want to reload this file in the REPL to update some modified functions in the file. If the type is parameterized then this will fail even though the type definition does not change.

Example:


julia> type Foo
       a::Int
       end

julia> type Foo
       a::Int
       end

julia> type Foo2{T}
       a::T
       end

julia> type Foo2{T}
       a::T
       end
ERROR: invalid redefinition of constant Foo2


Is there a good way to work around this? I don't really want to workspace() all the time because then I have to compile everything again.

Stefan Karpinski

unread,
Feb 11, 2016, 12:16:46 PM2/11/16
to Julia Users
Defining types in a module and then reloading the module helps. The bindings get messy though, so it's best to qualify all accesses when you're developing like that. This is kind of an annoyance – not sure how hard it would be to fix but it should be doable.

Kristoffer Carlsson

unread,
Feb 11, 2016, 12:21:51 PM2/11/16
to julia-users
Modules might work but they bring other annoyances... I would be fine with a warning and just ignoring the whole type block.

Similar to:

julia> const a = 1
1

julia> const a = 2
WARNING: redefining constant a
2

couldn't it be:

julia> type Foo2{T}
       a::T
       end

julia> type Foo2{T}
       a::T
       end
WARNING: did not redefine constant Foo2

Stefan Karpinski

unread,
Feb 11, 2016, 12:32:06 PM2/11/16
to Julia Users
You could also make the type definition conditional and only evaluate it if it isn't already defined.

Kristoffer Carlsson

unread,
Feb 11, 2016, 12:53:11 PM2/11/16
to julia-users
Ah, that's a good idea! Thanks!
Reply all
Reply to author
Forward
0 new messages