Created
October 21, 2020 15:15
-
-
Save phasetr/03d408773923f9b73284322f85a1d19c 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
struct Point | |
x::Int | |
y::Int | |
end | |
mutable struct Point{T} | |
x::T | |
y::T | |
end | |
println(Point{Int} <: Point) # true | |
println(Point{Int} <: Point{Number}) # false | |
println(Point{Int} <: Point{Float64}) # false |
Julia 1.5.2、P.52 にある次のコードが通る?
function distance(p::Point{Number})
sqrt(p.x^2 + p.y^2)
end
ちなみに struct Point
を定義せずに直接 struct Point{T}
を定義している。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1から始めるJulia、P51 で下3行の確認があるが、Julia1.5.2 だと
mutable struct Point{T}
の定義の段階でERROR: invalid redefinition of constant Point
が出る。そもそもmutable
がある時点で気に食わないという話もあるが、これはバージョンアップで挙動が変わった事案?