Skip to content

Instantly share code, notes, and snippets.

@phasetr
Created October 21, 2020 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phasetr/03d408773923f9b73284322f85a1d19c to your computer and use it in GitHub Desktop.
Save phasetr/03d408773923f9b73284322f85a1d19c to your computer and use it in GitHub Desktop.
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
@phasetr
Copy link
Author

phasetr commented Oct 21, 2020

1から始めるJulia、P51 で下3行の確認があるが、Julia1.5.2 だと mutable struct Point{T} の定義の段階で ERROR: invalid redefinition of constant Point が出る。そもそも mutable がある時点で気に食わないという話もあるが、これはバージョンアップで挙動が変わった事案?

@phasetr
Copy link
Author

phasetr commented Oct 21, 2020

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