Created
August 10, 2016 18:32
-
-
Save latticetower/004c3e0d30dc761d0e6b824cf19278e3 to your computer and use it in GitHub Desktop.
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 C0{T} | |
super :: T#base obj | |
x :: Int#subtype fields | |
function C0(x::Int, y::Int) | |
new(T(x), y) # вызвали конструктор базового типа, если надо, ну и добавили сложную логику | |
end | |
end | |
function convert{T}(::Type{C0{T}}, x::Int, y::Int) | |
C0{T}(x, y) | |
end | |
a=C0{Int}(1,2) #но в качестве параметра надо явно указывать базовый тип | |
typeof(a.super) | |
type Rep | |
x::Int | |
y::Int | |
Rep(x::Int)=new(x, x) | |
end | |
#какой-то псевдо-базовый класс | |
b=C0{Rep}(1,2) | |
b.super | |
# если мы хотим вызывать "дочерний" тип в функциях, которые определены для базового, можно вот это доопределить | |
function convert{T}(::Type{T}, child :: C0{T}) | |
child.super | |
end | |
convert(Rep, b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment