3#4SVCZTJHOBUVSF
w 3#4ΛಡΜͰɺΫϥεఆٛͷใΛॲཧ͢ΔϥΠϒϥϦ
w ৄ͘͠དྷिͷ3VCZ)BDL$IBMMFOHF)PMJEBZͰ
IUUQTSIDDPOOQBTTDPNFWFOU
class Set[A]
def initialize: (_Each[A, untyped]) -> void
| () -> void
def intersection: (_Each[A, untyped]) -> self
...
end
Slide 12
Slide 12 text
ΞτϥΠϯ
w 3VCZͷ
w ܕͳ͠ݴޠͷͨΊͷܕ
w 5ZQF4DSJQUͱ࠷ۙͷྲྀΕ
w 3VCZͷͨΊͷܕ
Slide 13
Slide 13 text
ܕͳ͠ݴޠͷͨΊͷܕ
w ܕ
w ίϯύΠϧ࣌ʹ໌͢Δࣜͷଐੑ
w ͋ΔछͷޡΓΛݕग़Ͱ͖Δʢܕݕࠪʣ
w ܕͳ͠ݴޠ
w ίϯύΠϧ࣌ʹܕݕࠪ͞Εͳ͍ݴޠʢ㲈ಈతܕ͚ݴޠʣ
w 3VCZͱ͔
Slide 14
Slide 14 text
ίʔυฤू
ίϯύΠϧ
࣮ߦ
ܕݕࠪ
ίʔυฤू
ίϯύΠϧ
࣮ߦ
ܕݕࠪ
Slide 15
Slide 15 text
class Person
def name
@name
end
def name=(value)
@name = value
end
end
if rand(10) < 5
person = Person.new
person.nme = "Soutaro Matsumoto" # NoMethodError
end
w ܕݕࠪʹΑͬͯɺཏతʹʢJGͷதʣݕࠪ͞Εͯɺ࣮
ߦલʹ͕ݕग़͞ΕΔʢίϯύΠϧ࣌ʣ
w ܕݕࠪ͠ͳ͍߹ʹɺϓϩάϥϜͷ࣮ߦঢ়گʹΑͬ
ͯɺ͕ݟ͔ͭΒͳ͍ʢ࣮ߦ࣌ʣ
Slide 16
Slide 16 text
ܕݕࠪͷಘࣦ
w ͕ࣄલʹݕग़Ͱ͖Δ
w ཏతͳݕࠪʢ࣮ߦͷύεʹґଘ͠ͳ͍ʣ
w ॻ͚ΔϓϩάϥϜʹ੍ݶ͕ՃΘΔ
w ࣮ࡍʹ࣮ߦ͞Εͳ͍ύεʹ͍ͭͯݕࠪ͞Εͯ͠·͏
.-ͷܕਪ
w ʮ࠙ஸೡʹશ෦ͷࣜʹܕΛॻ͔ͳͯ͘ྑ͍ʯͱ͍͏ൃݟ
w ύϥϝʔλଟ૬ʢେମ(FOFSJDTͷ͜ͱʣ
# let rec map f xs = match xs with
[] -> []
| x::xs -> f x :: map f xs;;
val map : ('a -> 'b) -> 'a list -> 'b list =
Slide 22
Slide 22 text
4PGU5ZQJOH
w ܕͳ͠ͷݴޠʹܕΛ͚͍ͨ
w ܕ͕͍ͭͨ෦Τϥʔ͕ݕग़Ͱ͖Δ
w Θ͔Βͳ͍ͷ࣮ߦ࣌ʹݕࠪ͢Δ
w ಈ͘ϓϩάϥϜͰ͖Δ͚ͩͦͷ··ܕݕࠪΛ௨͍ͨ͠
w ܕऍઈରॻ͖ͨ͘ͳ͍
Slide 23
Slide 23 text
6OJPOUZQFT
def f(x)
if x
1
else
"2"
end
end
Slide 24
Slide 24 text
6OJPOUZQFT
def f(x)
if x
1
else
"2"
end
end
(bool) -> (Integer | String)
Slide 25
Slide 25 text
'MPXTFOTJUJWF5ZQJOH
def g(n)
n.abs # NoMethodError
n.bytes # n: Integer | String
case n
when Integer
n.abs # n: Integer
when String
n.bytes # n: String
end
end
(Integer | String) -> Integer
Slide 26
Slide 26 text
4PGU5ZQJOH
w 4DIFNFϓϩάϥϜͷܕ͚ʹඞཁͳͷ͕Θ͔ͬͨ
w 6OJPOUZQFT
'MPXTFOTJUJWFUZQJOH
w ࣮
w .-ͷܕਪʹجͮ͘ͷ
w ϑϩʔղੳ͢Δͷ
Slide 27
Slide 27 text
ͬͱۙతͳݴޠͰʁ
w +BWB4DSJQUͱ͔3VCZͱ͔<
>
w ΦϒδΣΫτʹର͢Δଟ૬ੑ BLBμοΫλΠϐϯά
w ʮ͋Δϝιου͕ఆٛ͞Ε͍ͯΔҙͷΫϥεʯΈ͍ͨͳܕ
def add(x, y)
x + y
end
def add: [A, B] ({ +: (A) -> B }, A) -> B
Slide 28
Slide 28 text
3VCZͰࢼͨ͠ͱ͜Ζ
w ͬͺΓݫ͍͠
w .-ͷܕਪͰॲཧͰ͖ͳ͍ఆ͕ٛͰͯ͘Δ "SSBZNBQ
w Ϋϥεఆ໋͕ٛྩతʹมΘ͍ͬͯ͘ͷ͕ݫ͍͠ʢϝλϓϩάϥϛϯάʣ
w ͦͦյΕ͍ͯΔఆ͕ٛͨ͘͞Μ͋Δ
w "SSBZTFMFDUWT0CKFDUTFMFDU
w )BTIΛฦ͢IBTIΛఆٛͨ͜͠ͱ͕ͳ͍ਓ
Slide 29
Slide 29 text
"SSBZJTB0CKFDU
w 0CKFDUʹରͯ͠ಈ͘ϓϩάϥϜ"SSBZʹରͯ͠ಈ͘ʁʁ
class Object
def use_select
select [STDIN], [], []
end
end
"".use_select # OK
[1,2,3].use_select # ????
Slide 30
Slide 30 text
4PGU5ZQJOH͔ΒಘΒΕͨݟ
w จͰޭ͍ͯ͠ΔΑ͏ʹݟ͑Δ͕࣮༻Ϩϕϧͷͷͳ͍
w ඞཁͦ͏ͳܕγεςϜͷػೳΘ͔͖ͬͯͨ
w Ή͠ΖܕΛॻ͍ͨํ͕ྑ͍ͷͰʁʁ
w ϓϩάϥϚͷҙਤΛܕͰදݱ͢Δ
w ҙਤͱҰக͠ͳ͍ίʔυΛݕग़͢Δ
Slide 31
Slide 31 text
(SBEVBM5ZQJOH
w ਐతܕ͚
w ܕͳ͠ͷίʔυͱܕ͖ͭͷίʔυΛࠞͥΔ
w ͩΜͩΜܕΛ͚͍ͯ͘
w ܕॻ͘
Slide 32
Slide 32 text
ܕͳ͠ݴޠͷͨΊͷܕ
w ͦΕͳΓʹڧྗͳܕγεςϜ
w 6OJPOUZQFT
qPXTFOTJUJWFUZQJOH
HFOFSJDT
w μοΫλΠϐϯά
w ߏత෦ܕ
w ΫϥεͷܧঝؔΛ͋ͱͰมߋͰ͖ΔΈ )BTLFMM
4XJGU
$
w (SBEVBM5ZQJOH
Slide 33
Slide 33 text
ΞτϥΠϯ
w 3VCZͷ
w ܕͳ͠ݴޠͷͨΊͷܕ
w 5ZQF4DSJQUͱ࠷ۙͷྲྀΕ
w 3VCZͷͨΊͷܕ
Slide 34
Slide 34 text
࠷ۙͷྲྀߦ
w ܕ͖ͭͷํݴ
w 5ZQF4DSJQU
5ZQFE4DIFNF
w ܕऍͷαϙʔτ
w 1ZUIPO
1)1
5ZQF4DSJQUͷ͍͢͝ͱ͜Ζ
w ܕͳ͠ݴޠʹܕΛ͚Δਓྨͷເ͕ͬͨ
w ΈΜͳܕΛॻ͍͍ͯΔͷ͕͍͢͝
w ߏతͳܕ͚ͩͰͳΜͱ͔ͳͬͯΔͷ͕͍͢͝
w 6OJPOUZQFTͱ͔qPXTFOTJUJWFUZQFTͱ͔MPHJDBMUZQFTͱ͔͠Εͬͱ
ೖͬͯΔͷ͕͍͢͝
w ϥϯλΠϜͱͷ੍ΛΓӽ͑ͯಈ͍ͯΔͷ͕͍͢͝
Slide 37
Slide 37 text
ܕॻ͔ͳ͍͚ͯ͘ͳ͍
w ΑͬΆͲࣗ໌ͳͷҎ֎ॻ͘
w ϥΠϒϥϦͷܕEFpOJUFMZUZQFEʹू·͍ͬͯΔ
const numbers: number[] = [1,2,3]
numbers.map(x => x.toString())
6OJPO5ZQFT'MPXTFOTJUJWF5ZQJOH
w OVMMVOEFpOFEͱ͏·͘ΕΔΑ͏ʹͳͬͨ
const x: string | undefined = ...
// Object is possibly 'undefined'.
x.toUpperCase()
if (x) {
x.toUpperCase()
}
Slide 43
Slide 43 text
ϥϯλΠϜͷ੍
w +4ͷϥϯλΠϜʹͰ͖ͳ͍͜ͱ54ͰͰ͖ͳ͍
w ʮ͋Δ͕ΠϯλʔϑΣʔεʹద߹͍ͯ͠Δ͔ݕ͍ࠪͨ͠ʯ
w Ϣʔβʔ͕ࣗͷͰݕূ͢Δ -PHJDBMUZQFT
• function isPants(object: any): object is Pants {
return object.type == "pants"
}
Slide 44
Slide 44 text
ݟ
w ਓؒܕΛॻ͘
w ʢܕΛॻ͖ͨ͘ͳ͍ਓ5ZQF4DSJQUΛΘͳ͍ͷͰ؍ଌͰ͖ͳ͍ʣ
w େମ+BWB4DSJQUͷίʔυʹܕ͕ͭ͘
w 6OJPOUZQFTͱ͔qPXTFOTJUJWFUZQJOHͱ͔͕ॏཁ
w ߏత෦ܕಈ͘
w ϥϯλΠϜͷ੍ݶΛΓӽ͑ΔͨΊ JTܕ
Slide 45
Slide 45 text
1ZUIPO
1)1
w ϝιουͷܕΛॻ͘ه๏͕ಋೖ͞Εͨ
w ܕݕ࣮ࠪߦ࣌
w ϝιουݺͼग़͠ͷͱ͖ʹܕݕࠪ͢Δ
w ੩తͳܕݕࠪث։ൃ͞Ε͍ͯΔ
function sum(int $a, int $b) {
return $a + $b;
}
Slide 46
Slide 46 text
ΞτϥΠϯ
w 3VCZͷ
w ܕͳ͠ݴޠͷͨΊͷܕ
w 5ZQF4DSJQUͱ࠷ۙͷྲྀΕ
w 3VCZͷͨΊͷܕ
Slide 47
Slide 47 text
3VCZͷͨΊͷܕ
w 4PGUUZQJOHͷݟˠਪΛؤுΔͷઓతʢ!NBNFʣ
w 5ZQF4DSJQUͷݟ
w ਓྨܕΛॻ͘
w ͦΕͳΓʹڧྗͳܕγεςϜ͕͋Ε্ख͘Εͦ͏
w 1ZUIPO
1)1ͷݟ
w ܕऍܾΊͳ͍ͱ͍͚ͳ͍
w ܕݕࠪثผπʔϧʹ͢Δ
Slide 48
Slide 48 text
ܕऍͷه๏ 3#4
w গͳ͘ͱϥΠϒϥϦͷܕΛॻ͘ํ๏͕ඞཁ
w ܕݕࠪπʔϧ͕ͦΕͧΕʹ༻ҙ͢Δͷ͔ͳΓݫ͍͠
w ϥϯλΠϜͷݕ͕ࠪͰ͖Δ͚ͩͰͦΕͳΓʹخ͍͠Ͱʁ
w ιʔείʔυʹຒΊࠐΉߏจ࠾༻͠ͳ͍
Slide 49
Slide 49 text
ΈࠐΈͷܕऍߏจʢෆ࠾༻ʣ
class Box
extend T::Sig
extend T::Generic
Elem = type_member
sig {returns(Elem)}
# @type var box: Box[Integer]
box = Box.new
box.x = "hello"
&NCFEEFE%4- 4PSCFU
$PNNFOUT 4UFFQ
class Box [A]
def value: A; ...; end
def value=(value: A): A; ...; end
end
a: Box[Integer] = Box.new
Slide 50
Slide 50 text
ͦΕͳΓʹϦονͳܕ
w λϓϧɺϨίʔυ
[Integer, Symbol]
w Ϧςϥϧܕ
1, "hello", :world
w 6OJPOUZQFT
Integer | String
w 0QUJPOBMUZQFTɺ(FOFSJDTʜ
Array[String]?
w յΕ͍ͯΔͷJODPNQBUJCMF
incompatible
def select: [A] () { (Elem) -> A
Slide 51
Slide 51 text
μοΫλΠϐϯά
w JOUFSGBDFΛఆٛͯ͠ɺཁٻ͞ΕΔϝιουͷू߹Λॻ͘
w ϝιου͕͋Δ͔ͳ͍͔Ͱݕࠪ͞ΕΔ
interface _Push
def <<: (String) -> void
end
def foo: (_Push) -> void
def foo(a)
a << "hello"
end
foo []
foo ""
foo 3 # Τϥʔ
Slide 52
Slide 52 text
࣮ߦ࣌ݕ͚ࠪͩͰ
w γάωνϟΛॻ͍ͨΒɺϢχοτςετͰςετ͢Δํ๏Λఏڙ
w ϝιουݺͼग़͠ͷલޙʹܕݕࠪΛૠೖ
w IUUQTSIDDPOOQBTTDPNFWFOU
$ RBS_TEST_TARGET='Goodcheck::*' \
RBS_TEST_RAISE=true \
RUBYOPT='-rbundler/setup -rruby/signature/test/setup' \
RBS_TEST_OPT='-rset -rpathname -Isig' \
bundle exec rake test
Slide 53
Slide 53 text
IUUQTHJUIVCDPNTJEFSHPPEDIFDLUSFFSCT
Slide 54
Slide 54 text
·ͱΊ
w 4PGUUZQJOHΈ͍ͨʹਪΛؤுΔͷ߹ཧతͰͳ͍
w ܕΛॻ͔ͳ͍ͷݫ͍͠
w ਓؒܕΛॻ͘ʢ͜͜ͰಘΒΕͨݟʣ
w 3VCZͷͨΊͷܕ
w ΘΓͱϦονͳܕ(FOFSJDTɺ6OJPOUZQFTɺ'MPXTFOTJUJWFUZQJOH
w μοΫλΠϐϯάؤுΔʢߏత෦ܕʣ
Slide 55
Slide 55 text
w <$BSUXSJHIU
>3$BSUXSJHIUBOE.'BHBO4PGUUZQJOH
w <.BUTVNPUP
>4.BUTVNPUPBOE:.JOBNJEF5ZQF*OGFSFODFGPS3VCZ
1SPHSBNTCBTFEPO1PMZNPSQIJD3FDPSE5ZQFT
w <+FOTFO
>4)+FOTFOBOE".MMFSBOE15IJFNBOO
5ZQF"OBMZTJTGPS
+BWB4DSJQU
w <4JFL
>+4JFLBOE85BIB
(SBEVBM5ZQJOHGPS0CKFDUT
w <)PDITUBEU
>45)PDITUBEU
5ZQFE4DIFNF'SPN4DSJQUTUP1SPHSBNT
w