-
-
Save HarlanH/1910073 to your computer and use it in GitHub Desktop.
playing with NA for Julia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type _NA | |
end | |
macro NA() # for easier typing! | |
_NA() | |
end | |
NumberData = Union(_NA, Number) | |
StringData = Union(_NA, String) | |
# is there a way to avoid having to write down rules like this for every | |
# basic data type? | |
promote_rule(::Type{_NA}, ::Type{Int64}) = NumberData | |
promote_rule(::Type{_NA}, ::Type{Float64}) = NumberData | |
promote_rule(::Type{_NA}, ::Type{ASCIIString}) = StringData | |
# and likewise? | |
promote_rule(::Type{NumberData}, ::Type{Int64}) = NumberData | |
promote_rule(::Type{NumberData}, ::Type{Float64}) = NumberData | |
promote_rule(::Type{StringData}, ::Type{ASCIIString}) = StringData | |
# This works, but will we need to do it for EVERY operator? | |
+(x::_NA, y::Number) = @NA | |
show(na::_NA) = print("NA") | |
is_na(x) = typeof(x) == _NA | |
# try it out: | |
qq = ["asdf", "qwerty", @NA, "biff"] | |
qq[!map(is_na, qq)] | |
map(uc, qq) # fails -- will we have to change EVERY core function? | |
zz = [1:3, @NA, 5:6] | |
zz + 1 | |
sqrt(zz) # fails -- same issue | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment