Created
October 21, 2016 01:44
-
-
Save andyferris/b1bd9d4f251e00bc3639d4ae47868e41 to your computer and use it in GitHub Desktop.
Using a `?` as a nullable typename
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
module Maybe | |
export ? | |
immutable ?{T} | |
hasvalue::Bool | |
value::T | |
?() = new(false) | |
?(x::T) = new(true, x) | |
end | |
?{T}(x::T) = ?{T}(x) | |
?{T}(::Type{T}) = ?{T}() | |
Base.:*(::Type{?}, x) = ?(x) # I'm confused... ? is a unary in the Scheme file | |
function Base.show{T}(io::IO, x::?{T}) | |
if x.hasvalue | |
print(io, x.value) | |
else | |
print(io, "?(", T, ")") | |
end | |
end | |
end # module |
On this note we have ?
, !
, ¿
and ¡
(spanish style inverted question/exclamation marks). And unicode defines a reverse question mark ⸮
which wikipedia describes as the irony mark. Between these you could develop a whole language for get
, isnull
/hasvalue
, construction, type names, module names, and so-on.
Interesting. Though it would still be good to have a real name for that type, with ?
only an alias. Else, searches are going to be hard, and for dispatch x::?{T}
looks really weird.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Kind of amusing. E.g.