Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,20 @@ end

Val(x) = (@_pure_meta; Val{x}())

eltype(::Val{T}) where T = T
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't correct. T can be Array{S,N}, in which case eltype(Val{Array{S,N}}) should be S. I'd instead make this eltype(::Val{T}) where {T} = eltype(T).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm maybe eltype isn't the right name for what I want. I just want a function that will turn Val{:a}() into :a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, might be consistent with this:

Julia-0.7.0-DEV> x = Vector{Array{Int,3}}()
0-element Array{Array{Int64,3},1}

Julia-0.7.0-DEV> eltype(x)
Array{Int64,3}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Val isn't a collection or the type of a collection so eltype is not appropriate here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean I could just leave it out this PR, or choose another name? devalue?


(&)(v1::Val{true}, v2::Val{true}) = Val{true}()
(&)(v1::Val, v2::Val) = Val{false}()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these methods seem to cover too many possibilities; I'd suggest to just write out all four combinations


(|)(v1::Val{false}, v2::Val{false}) = Val{false}()
(|)(v1::Val, v2::Val) = Val{true}()

!(::Val{false}) = Val{true}()
!(::Val{true}) = Val{false}()

ifelse(switch::Val{false}, new, old) = old
ifelse(switch::Val{true}, new, old) = new

# used by interpolating quote and some other things in the front end
function vector_any(@nospecialize xs...)
n = length(xs)
Expand Down