77 lines
1.9 KiB
Julia
77 lines
1.9 KiB
Julia
### A Pluto.jl notebook ###
|
|
# v0.12.6
|
|
|
|
using Markdown
|
|
using InteractiveUtils
|
|
|
|
# ╔═╡ 57970f5a-1ba2-11eb-2e5e-c150bd730b65
|
|
struct Foo
|
|
bar # Any
|
|
baz::Int
|
|
qux::Float64
|
|
end
|
|
|
|
# ╔═╡ f156f116-1ba2-11eb-2d84-f9f02380f42d
|
|
typeof(Foo)
|
|
|
|
# ╔═╡ 7ff7efd8-1ba3-11eb-1247-7d69a45fca1d
|
|
fieldnames(Foo)
|
|
|
|
# ╔═╡ 8b309210-1ba3-11eb-33a1-977e8fc172d2
|
|
fieldtypes(Foo)
|
|
|
|
# ╔═╡ f5c339a8-1ba2-11eb-3d75-dfa770226a9b
|
|
f = Foo(0, 1, 3.4)
|
|
|
|
# ╔═╡ f7760d60-1ba3-11eb-2bb6-85ea174dcd7f
|
|
f.qux
|
|
|
|
# ╔═╡ 294b331e-1ba3-11eb-23b1-1befbcafd110
|
|
# bar is not Any but a specific type
|
|
map(typeof, (f.bar, f.baz, f.qux))
|
|
|
|
# ╔═╡ 7e1b1b9a-1ba3-11eb-0ac9-23f4f325e05c
|
|
# Foo is not assignable
|
|
f.qux = 3.8
|
|
|
|
# ╔═╡ 198e17c6-1ba4-11eb-3af2-f3f8b1180eb8
|
|
mutable struct BankAccount
|
|
money :: Int
|
|
end
|
|
|
|
# ╔═╡ 3abe2a5a-1ba4-11eb-0830-3d7c2e889e31
|
|
bk = BankAccount(3)
|
|
|
|
# ╔═╡ 46274816-1ba4-11eb-08a3-47bc4a9a92bd
|
|
bk.money += 10
|
|
|
|
# ╔═╡ b26554dc-1ba4-11eb-30cb-9f2c5900042d
|
|
# union types = haskell datatypes
|
|
MaybeString = Union{Int, Nothing}
|
|
|
|
# ╔═╡ 331e0f08-1ba5-11eb-3d57-ab4f856042fb
|
|
s = 3::MaybeString
|
|
|
|
# ╔═╡ 39908440-1ba5-11eb-3360-d10fcbc18b56
|
|
typeof(s)
|
|
|
|
# ╔═╡ 7010b83a-1bb1-11eb-19ca-15f4270b7597
|
|
|
|
|
|
# ╔═╡ Cell order:
|
|
# ╠═57970f5a-1ba2-11eb-2e5e-c150bd730b65
|
|
# ╠═f156f116-1ba2-11eb-2d84-f9f02380f42d
|
|
# ╠═7ff7efd8-1ba3-11eb-1247-7d69a45fca1d
|
|
# ╠═8b309210-1ba3-11eb-33a1-977e8fc172d2
|
|
# ╠═f5c339a8-1ba2-11eb-3d75-dfa770226a9b
|
|
# ╠═f7760d60-1ba3-11eb-2bb6-85ea174dcd7f
|
|
# ╠═294b331e-1ba3-11eb-23b1-1befbcafd110
|
|
# ╠═7e1b1b9a-1ba3-11eb-0ac9-23f4f325e05c
|
|
# ╠═198e17c6-1ba4-11eb-3af2-f3f8b1180eb8
|
|
# ╠═3abe2a5a-1ba4-11eb-0830-3d7c2e889e31
|
|
# ╠═46274816-1ba4-11eb-08a3-47bc4a9a92bd
|
|
# ╠═b26554dc-1ba4-11eb-30cb-9f2c5900042d
|
|
# ╠═331e0f08-1ba5-11eb-3d57-ab4f856042fb
|
|
# ╠═39908440-1ba5-11eb-3360-d10fcbc18b56
|
|
# ╠═7010b83a-1bb1-11eb-19ca-15f4270b7597
|