Successfully reported this slideshow.
Upcoming SlideShare
×

# 型にはまらない型の話

375 views

Published on

プログラミングの話をすると二言目には型(type)の話になるものですが、それでは型とは一体なんでしょう?楽に楽しく型について、時間の許す範囲でカタります。

* 型の意味=型は意味
* Typeは楽、Typingは楽しい
* Perl5が愛され嫌われる理由
* Perl6:楽土は楽か?
* 型推論=いいとこ取り?

https://yapcjapan.org/2019tokyo/timetable.html#/detail/9

Published in: Software
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

### 型にはまらない型の話

1. 1. @dankogai
2. 2. Table of Contents • = • Type Typing • Perl5 • Perl6: ? • = ? • …
3. 3. What is this? 0101100101000001010100000100001101000001010100110100100101000001
4. 4. What is this? •Number 6431509992650787137? •Address 0x5941504341534941? •String q{YAPCASIA}? 0101100101000001010100000100001101000001010100110100100101000001
5. 5. It’s up to the type •Number 6431509992650787137? •Address 0x5941504341534941? •String “YAPCASIA”? 0101100101000001010100000100001101000001010100110100100101000001
6. 6. What is a \$scalar? •Boolean: true or false •Integer •Double •String •Bytes •UTF-8 •reference
7. 7. What is a \$scalar? •Boolean: true •Number: 0 •String “0 but true”? 0 but true
8. 8. What is the type of \$a? •Boolean: !!\$a •Number: 0+\$a •String q{} . \$a my \$a = q{0 but true};
9. 9. What does this say? say localtime;
10. 10. What does this say? say q{}.localtime;
11. 11. Perl 5 = context-oriented •Most languages: type is set when declared or assigned •Perl: type is set when used.
12. 12. Smart types #!/usr/bin/env /friends/.rakudobrew/bin/perl6 my subset Fizz of Int where * %% 3; my subset Buzz of Int where * %% 5; my subset FizzBuzz of Int where Fizz&Buzz; my subset Number of Int where none Fizz|Buzz; proto sub fizzbuzz (\$) { * } multi sub fizzbuzz (FizzBuzz) { "FuzzBuzz" } multi sub fizzbuzz (Fizz) { "Fizz" } multi sub fizzbuzz (Buzz) { "Buzz" } multi sub fizzbuzz (Number \$number) { \$number } fizzbuzz(\$_).say for 1..30; http://eval.dan.co.jp/ﬁzzbuzz.html#perl6
13. 13. Inferred types #!/usr/local/bin/swift extension Int { var fizzbuzz:String { let fb = ("Fizz", "Buzz") switch (self % 3, self % 5) { case (0, 0) : return fb.0 + fb.1 case (0, _) : return fb.0 case (_, 0) : return fb.1 default : return "(self)" } } } _ = (1...30).map{ print(\$0.fizzbuzz) } http://eval.dan.co.jp/ﬁzzbuzz.html#swift
14. 14. Wrap-up •Type = meaning of data •Perl 5 is special •lazy typing? •Future of types •Perl 6: subtype •Type inference: Haskell, Rust, Swift, SPVM?
15. 15. That’s it answer \$_ for @questions;