-
Notifications
You must be signed in to change notification settings - Fork 10
Properly display derived types of AbstractSet
in REPL or IJulia
#40
Comments
Can you please point out in the codebase where you think |
Indeed no Given an object Since no method function show(io::IO, ::MIME"text/plain", t::AbstractSet{T}) where T The object Overall, the issue can be easily fixed by providing |
I can reproduce the issue, thanks for reporting. Do you mind submitting a PR with the |
I encountered the issue when playing with Reinforce.jl, and the essential reason is in
LearnBase
.Issue description:
When a concrete type in
LearnBase
derived fromAbstractSet
is displayed automatically in REPL or IJulia (i.e., with no semicolon at the end), an error will be caused like follows:How to reproduce
Note that, if you suppress the output with a semicolon and then print it manually with
print(ds)
, then no error happens and the printed result isLearnBase.DiscreteSet{Array{Int64,1}}([1, 2, 3])
.Reason of the error
The reason is that when a variable is displayed automatically in REPL or IJulia, the
display
function is used. That is, if you print the output withdisplay(ds)
, the same error is induced. It seems that, for subtypes ofAbstractSet
, the defaultdisplay
method tries to iterate over each element. However, there is no default implementation in Julia to iterate anAbstractSet
. (see documentation)Possible fix
Two obvious fixes are possible
Base.iterate
method for each related type inLearnBase
.Example: if we dispatch
Base.iterate
forDiscreteSet
by iteratingDiscreteSet.items
, the displayed output of the aboveds
isHowever, an iteration method may make little sense for
LearnBase.IntervalSet
.display
by implementing the MIMEshow
method for relevant types. (see documentation)Example:
will display a
LearnBase.IntervalSet(-1.0, 1.0)
asMy suggestion is that
AbstractSet
pertaining to this issue.DiscreteSet
), implement alsoBase.iterate
. Another benefit is that, with iteration support, those types can be used in a for loop naturally.I can make a PR if you think the above suggestion is reasonable.
The text was updated successfully, but these errors were encountered: