The document discusses the ATS programming language as a safer alternative to C for systems programming. ATS includes features like dependent types, linear types, and optional garbage collection that could help prevent bugs like Heartbleed. Examples show implementing FizzBuzz in both Standard ML and ATS. The ATS code compiles to C and can run on bare metal without an operating system.
1. ATS language overviewATS language overviewATS language overviewATS language overviewATS language overview
Kiwamu OkabeKiwamu OkabeKiwamu OkabeKiwamu OkabeKiwamu Okabe
2. Remember Heartbleed bug?Remember Heartbleed bug?Remember Heartbleed bug?Remember Heartbleed bug?Remember Heartbleed bug?
Should we use safer language than C?Should we use safer language than C?Should we use safer language than C?Should we use safer language than C?Should we use safer language than C?
== In English ==
"Preventing heartbleed bugs with safe programming languages"
http://bluishcoder.co.nz/2014/04/11/preventing-heartbleed-bugs-
with-safe-languages.html
== In Japanease ==
"安全なプログラミング言語を使って heartbleed を防ぐには"
https://github.com/jats-ug/translate/blob/master/Web/
bluishcoder.co.nz/2014/04/11/preventing-heartbleed-bugs-with-safe-
languages.md
== In English ==
"Preventing heartbleed bugs with safe programming languages"
http://bluishcoder.co.nz/2014/04/11/preventing-heartbleed-bugs-
with-safe-languages.html
== In Japanease ==
"安全なプログラミング言語を使って heartbleed を防ぐには"
https://github.com/jats-ug/translate/blob/master/Web/
bluishcoder.co.nz/2014/04/11/preventing-heartbleed-bugs-with-safe-
languages.md
== In English ==
"Preventing heartbleed bugs with safe programming languages"
http://bluishcoder.co.nz/2014/04/11/preventing-heartbleed-bugs-
with-safe-languages.html
== In Japanease ==
"安全なプログラミング言語を使って heartbleed を防ぐには"
https://github.com/jats-ug/translate/blob/master/Web/
bluishcoder.co.nz/2014/04/11/preventing-heartbleed-bugs-with-safe-
languages.md
== In English ==
"Preventing heartbleed bugs with safe programming languages"
http://bluishcoder.co.nz/2014/04/11/preventing-heartbleed-bugs-
with-safe-languages.html
== In Japanease ==
"安全なプログラミング言語を使って heartbleed を防ぐには"
https://github.com/jats-ug/translate/blob/master/Web/
bluishcoder.co.nz/2014/04/11/preventing-heartbleed-bugs-with-safe-
languages.md
== In English ==
"Preventing heartbleed bugs with safe programming languages"
http://bluishcoder.co.nz/2014/04/11/preventing-heartbleed-bugs-
with-safe-languages.html
== In Japanease ==
"安全なプログラミング言語を使って heartbleed を防ぐには"
https://github.com/jats-ug/translate/blob/master/Web/
bluishcoder.co.nz/2014/04/11/preventing-heartbleed-bugs-with-safe-
languages.md
"A safer systems programming language
could have prevented the bug."
"A safer systems programming language
could have prevented the bug."
"A safer systems programming language
could have prevented the bug."
"A safer systems programming language
could have prevented the bug."
"A safer systems programming language
could have prevented the bug."
3. What is ATS?What is ATS?What is ATS?What is ATS?What is ATS?
☆ http://www.ats-lang.org/☆ http://www.ats-lang.org/☆ http://www.ats-lang.org/☆ http://www.ats-lang.org/☆ http://www.ats-lang.org/
☆ Syntax like ML☆ Syntax like ML☆ Syntax like ML☆ Syntax like ML☆ Syntax like ML
☆ DML-style dependent types☆ DML-style dependent types☆ DML-style dependent types☆ DML-style dependent types☆ DML-style dependent types
☆ Linear types☆ Linear types☆ Linear types☆ Linear types☆ Linear types
☆ Optional GC☆ Optional GC☆ Optional GC☆ Optional GC☆ Optional GC
☆ Optional malloc/free☆ Optional malloc/free☆ Optional malloc/free☆ Optional malloc/free☆ Optional malloc/free
☆ Optional run-time☆ Optional run-time☆ Optional run-time☆ Optional run-time☆ Optional run-time
5. Fizzbuzz on Standard MLFizzbuzz on Standard MLFizzbuzz on Standard MLFizzbuzz on Standard MLFizzbuzz on Standard ML
(* http://rosettacode.org/wiki/FizzBuzz#Standard_ML *)
local
fun fbstr i =
case (i mod 3 = 0, i mod 5 = 0) of
(true , true ) => "FizzBuzz"
| (true , false) => "Fizz"
| (false, true ) => "Buzz"
| (false, false) => Int.toString i
fun fizzbuzz' (n, j) =
if n = j then ()
else (print (fbstr j ^ "n"); fizzbuzz' (n, j+1))
in
fun fizzbuzz n = fizzbuzz' (n, 1)
val _ = fizzbuzz 100
end
(* http://rosettacode.org/wiki/FizzBuzz#Standard_ML *)
local
fun fbstr i =
case (i mod 3 = 0, i mod 5 = 0) of
(true , true ) => "FizzBuzz"
| (true , false) => "Fizz"
| (false, true ) => "Buzz"
| (false, false) => Int.toString i
fun fizzbuzz' (n, j) =
if n = j then ()
else (print (fbstr j ^ "n"); fizzbuzz' (n, j+1))
in
fun fizzbuzz n = fizzbuzz' (n, 1)
val _ = fizzbuzz 100
end
(* http://rosettacode.org/wiki/FizzBuzz#Standard_ML *)
local
fun fbstr i =
case (i mod 3 = 0, i mod 5 = 0) of
(true , true ) => "FizzBuzz"
| (true , false) => "Fizz"
| (false, true ) => "Buzz"
| (false, false) => Int.toString i
fun fizzbuzz' (n, j) =
if n = j then ()
else (print (fbstr j ^ "n"); fizzbuzz' (n, j+1))
in
fun fizzbuzz n = fizzbuzz' (n, 1)
val _ = fizzbuzz 100
end
(* http://rosettacode.org/wiki/FizzBuzz#Standard_ML *)
local
fun fbstr i =
case (i mod 3 = 0, i mod 5 = 0) of
(true , true ) => "FizzBuzz"
| (true , false) => "Fizz"
| (false, true ) => "Buzz"
| (false, false) => Int.toString i
fun fizzbuzz' (n, j) =
if n = j then ()
else (print (fbstr j ^ "n"); fizzbuzz' (n, j+1))
in
fun fizzbuzz n = fizzbuzz' (n, 1)
val _ = fizzbuzz 100
end
(* http://rosettacode.org/wiki/FizzBuzz#Standard_ML *)
local
fun fbstr i =
case (i mod 3 = 0, i mod 5 = 0) of
(true , true ) => "FizzBuzz"
| (true , false) => "Fizz"
| (false, true ) => "Buzz"
| (false, false) => Int.toString i
fun fizzbuzz' (n, j) =
if n = j then ()
else (print (fbstr j ^ "n"); fizzbuzz' (n, j+1))
in
fun fizzbuzz n = fizzbuzz' (n, 1)
val _ = fizzbuzz 100
end
6. Fizzbuzz on ATSFizzbuzz on ATSFizzbuzz on ATSFizzbuzz on ATSFizzbuzz on ATS
#include "share/atspre_define.hats"
#include "share/atspre_staload.hats"
local
fun fbstr (i:int): string =
case (i mod 3 = 0, i mod 5 = 0) of
(true , true ) => "FizzBuzz"
| (true , false) => "Fizz"
| (false, true ) => "Buzz"
| (false, false) => tostring_int i
fun fizzbuzz' (n:int, j:int): void =
if n = j then ()
else (println! (fbstr j); fizzbuzz' (n, j+1))
in
fun fizzbuzz (n:int): void = fizzbuzz' (n, 1)
val _ = fizzbuzz 100
end
implement main0 () = ()
#include "share/atspre_define.hats"
#include "share/atspre_staload.hats"
local
fun fbstr (i:int): string =
case (i mod 3 = 0, i mod 5 = 0) of
(true , true ) => "FizzBuzz"
| (true , false) => "Fizz"
| (false, true ) => "Buzz"
| (false, false) => tostring_int i
fun fizzbuzz' (n:int, j:int): void =
if n = j then ()
else (println! (fbstr j); fizzbuzz' (n, j+1))
in
fun fizzbuzz (n:int): void = fizzbuzz' (n, 1)
val _ = fizzbuzz 100
end
implement main0 () = ()
#include "share/atspre_define.hats"
#include "share/atspre_staload.hats"
local
fun fbstr (i:int): string =
case (i mod 3 = 0, i mod 5 = 0) of
(true , true ) => "FizzBuzz"
| (true , false) => "Fizz"
| (false, true ) => "Buzz"
| (false, false) => tostring_int i
fun fizzbuzz' (n:int, j:int): void =
if n = j then ()
else (println! (fbstr j); fizzbuzz' (n, j+1))
in
fun fizzbuzz (n:int): void = fizzbuzz' (n, 1)
val _ = fizzbuzz 100
end
implement main0 () = ()
#include "share/atspre_define.hats"
#include "share/atspre_staload.hats"
local
fun fbstr (i:int): string =
case (i mod 3 = 0, i mod 5 = 0) of
(true , true ) => "FizzBuzz"
| (true , false) => "Fizz"
| (false, true ) => "Buzz"
| (false, false) => tostring_int i
fun fizzbuzz' (n:int, j:int): void =
if n = j then ()
else (println! (fbstr j); fizzbuzz' (n, j+1))
in
fun fizzbuzz (n:int): void = fizzbuzz' (n, 1)
val _ = fizzbuzz 100
end
implement main0 () = ()
#include "share/atspre_define.hats"
#include "share/atspre_staload.hats"
local
fun fbstr (i:int): string =
case (i mod 3 = 0, i mod 5 = 0) of
(true , true ) => "FizzBuzz"
| (true , false) => "Fizz"
| (false, true ) => "Buzz"
| (false, false) => tostring_int i
fun fizzbuzz' (n:int, j:int): void =
if n = j then ()
else (println! (fbstr j); fizzbuzz' (n, j+1))
in
fun fizzbuzz (n:int): void = fizzbuzz' (n, 1)
val _ = fizzbuzz 100
end
implement main0 () = ()
7. How to compile itHow to compile itHow to compile itHow to compile itHow to compile it
$ patscc -DATS_MEMALLOC_LIBC -o fizzbuzz fizzbuzz.dats
$ ls
fizzbuzz* fizzbuzz.dats fizzbuzz_dats.c
$ size fizzbuzz
text data bss dec hex filename
6364 796 40 7200 1c20 fizzbuzz
$ ldd fizzbuzz
linux-vdso.so.1 (0x00007ffefef06000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
(0x00007fd024f9b000)
/lib64/ld-linux-x86-64.so.2 (0x00005623ca0a6000)
$ ./fizzbuzz | head
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
$ patscc -DATS_MEMALLOC_LIBC -o fizzbuzz fizzbuzz.dats
$ ls
fizzbuzz* fizzbuzz.dats fizzbuzz_dats.c
$ size fizzbuzz
text data bss dec hex filename
6364 796 40 7200 1c20 fizzbuzz
$ ldd fizzbuzz
linux-vdso.so.1 (0x00007ffefef06000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
(0x00007fd024f9b000)
/lib64/ld-linux-x86-64.so.2 (0x00005623ca0a6000)
$ ./fizzbuzz | head
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
$ patscc -DATS_MEMALLOC_LIBC -o fizzbuzz fizzbuzz.dats
$ ls
fizzbuzz* fizzbuzz.dats fizzbuzz_dats.c
$ size fizzbuzz
text data bss dec hex filename
6364 796 40 7200 1c20 fizzbuzz
$ ldd fizzbuzz
linux-vdso.so.1 (0x00007ffefef06000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
(0x00007fd024f9b000)
/lib64/ld-linux-x86-64.so.2 (0x00005623ca0a6000)
$ ./fizzbuzz | head
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
$ patscc -DATS_MEMALLOC_LIBC -o fizzbuzz fizzbuzz.dats
$ ls
fizzbuzz* fizzbuzz.dats fizzbuzz_dats.c
$ size fizzbuzz
text data bss dec hex filename
6364 796 40 7200 1c20 fizzbuzz
$ ldd fizzbuzz
linux-vdso.so.1 (0x00007ffefef06000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
(0x00007fd024f9b000)
/lib64/ld-linux-x86-64.so.2 (0x00005623ca0a6000)
$ ./fizzbuzz | head
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
$ patscc -DATS_MEMALLOC_LIBC -o fizzbuzz fizzbuzz.dats
$ ls
fizzbuzz* fizzbuzz.dats fizzbuzz_dats.c
$ size fizzbuzz
text data bss dec hex filename
6364 796 40 7200 1c20 fizzbuzz
$ ldd fizzbuzz
linux-vdso.so.1 (0x00007ffefef06000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
(0x00007fd024f9b000)
/lib64/ld-linux-x86-64.so.2 (0x00005623ca0a6000)
$ ./fizzbuzz | head
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
9. What can ATS do?What can ATS do?What can ATS do?What can ATS do?What can ATS do?
☆ Write code on bare metal hardware☆ Write code on bare metal hardware☆ Write code on bare metal hardware☆ Write code on bare metal hardware☆ Write code on bare metal hardware
☆ Write code in Linux kernel☆ Write code in Linux kernel☆ Write code in Linux kernel☆ Write code in Linux kernel☆ Write code in Linux kernel
☆ Use strong type without any OS☆ Use strong type without any OS☆ Use strong type without any OS☆ Use strong type without any OS☆ Use strong type without any OS
☆ Prove code using dependent types☆ Prove code using dependent types☆ Prove code using dependent types☆ Prove code using dependent types☆ Prove code using dependent types
☆ Safely use malloc using linear types☆ Safely use malloc using linear types☆ Safely use malloc using linear types☆ Safely use malloc using linear types☆ Safely use malloc using linear types
☆ Safely use pointer using linear types☆ Safely use pointer using linear types☆ Safely use pointer using linear types☆ Safely use pointer using linear types☆ Safely use pointer using linear types
10. Demo running on bare metalDemo running on bare metalDemo running on bare metalDemo running on bare metalDemo running on bare metal
http://youtu.be/5uPue0Jo1nchttp://youtu.be/5uPue0Jo1nchttp://youtu.be/5uPue0Jo1nchttp://youtu.be/5uPue0Jo1nchttp://youtu.be/5uPue0Jo1nc
Arduino Uno hardware:Arduino Uno hardware:Arduino Uno hardware:Arduino Uno hardware:Arduino Uno hardware:
☆ 8-bit Harvard architecture☆ 8-bit Harvard architecture☆ 8-bit Harvard architecture☆ 8-bit Harvard architecture☆ 8-bit Harvard architecture
☆ Flash Memory: 32 KB☆ Flash Memory: 32 KB☆ Flash Memory: 32 KB☆ Flash Memory: 32 KB☆ Flash Memory: 32 KB
☆ SRAM: 2 KB☆ SRAM: 2 KB☆ SRAM: 2 KB☆ SRAM: 2 KB☆ SRAM: 2 KB
12. Proof: Curry–Howard in ATSProof: Curry–Howard in ATSProof: Curry–Howard in ATSProof: Curry–Howard in ATSProof: Curry–Howard in ATS
☆ Type: Function signature introduced
by keyword "fun"
☆ Type: Function signature introduced
by keyword "fun"
☆ Type: Function signature introduced
by keyword "fun"
☆ Type: Function signature introduced
by keyword "fun"
☆ Type: Function signature introduced
by keyword "fun"
☆ Program: Function body introduced
by keyword "implement"
☆ Program: Function body introduced
by keyword "implement"
☆ Program: Function body introduced
by keyword "implement"
☆ Program: Function body introduced
by keyword "implement"
☆ Program: Function body introduced
by keyword "implement"
☆ Proposition: Proof function signature
introduced by keyword "prfun"
☆ Proposition: Proof function signature
introduced by keyword "prfun"
☆ Proposition: Proof function signature
introduced by keyword "prfun"
☆ Proposition: Proof function signature
introduced by keyword "prfun"
☆ Proposition: Proof function signature
introduced by keyword "prfun"
☆ Proof: Proof function body
introduced by keyword "primplement"
☆ Proof: Proof function body
introduced by keyword "primplement"
☆ Proof: Proof function body
introduced by keyword "primplement"
☆ Proof: Proof function body
introduced by keyword "primplement"
☆ Proof: Proof function body
introduced by keyword "primplement"
13. Proof: style of functionsProof: style of functionsProof: style of functionsProof: style of functionsProof: style of functions
14. Proof: function signatureProof: function signatureProof: function signatureProof: function signatureProof: function signature
17. Proof: after compilingProof: after compilingProof: after compilingProof: after compilingProof: after compiling
Proof is erased at compile time.Proof is erased at compile time.Proof is erased at compile time.Proof is erased at compile time.Proof is erased at compile time.
18. Proof: pros of mixed functionProof: pros of mixed functionProof: pros of mixed functionProof: pros of mixed functionProof: pros of mixed function
You can write following application:You can write following application:You can write following application:You can write following application:You can write following application:
☆ Program without garbage collection☆ Program without garbage collection☆ Program without garbage collection☆ Program without garbage collection☆ Program without garbage collection
☆ Proof to prove the program☆ Proof to prove the program☆ Proof to prove the program☆ Proof to prove the program☆ Proof to prove the program
Good news for low-level programming!Good news for low-level programming!Good news for low-level programming!Good news for low-level programming!Good news for low-level programming!
19. Linear type: type of listLinear type: type of listLinear type: type of listLinear type: type of listLinear type: type of list
List defined with linear type.List defined with linear type.List defined with linear type.List defined with linear type.List defined with linear type.
20. Linear type: create listLinear type: create listLinear type: create listLinear type: create listLinear type: create list
Compile error occurs, if consuming is
forgotten.
Compile error occurs, if consuming is
forgotten.
Compile error occurs, if consuming is
forgotten.
Compile error occurs, if consuming is
forgotten.
Compile error occurs, if consuming is
forgotten.
21. Linear type: append listLinear type: append listLinear type: append listLinear type: append listLinear type: append list
23. Join "Japan ATS User Group" !Join "Japan ATS User Group" !Join "Japan ATS User Group" !Join "Japan ATS User Group" !Join "Japan ATS User Group" !
http://jats-ug.metasepi.org/http://jats-ug.metasepi.org/http://jats-ug.metasepi.org/http://jats-ug.metasepi.org/http://jats-ug.metasepi.org/
We translate following ATS documents
into Japanese.
We translate following ATS documents
into Japanese.
We translate following ATS documents
into Japanese.
We translate following ATS documents
into Japanese.
We translate following ATS documents
into Japanese.
* ATSプログラミング入門
http://jats-ug.metasepi.org/doc/ATS2/INT2PROGINATS/
* ATSプログラミングチュートリアル
http://jats-ug.metasepi.org/doc/ATS2/ATS2TUTORIAL/
* Effective ATS
https://github.com/jats-ug/translate/blob/master/Manual/
EffectiveATS.md
* ATSプログラミング入門
http://jats-ug.metasepi.org/doc/ATS2/INT2PROGINATS/
* ATSプログラミングチュートリアル
http://jats-ug.metasepi.org/doc/ATS2/ATS2TUTORIAL/
* Effective ATS
https://github.com/jats-ug/translate/blob/master/Manual/
EffectiveATS.md
* ATSプログラミング入門
http://jats-ug.metasepi.org/doc/ATS2/INT2PROGINATS/
* ATSプログラミングチュートリアル
http://jats-ug.metasepi.org/doc/ATS2/ATS2TUTORIAL/
* Effective ATS
https://github.com/jats-ug/translate/blob/master/Manual/
EffectiveATS.md
* ATSプログラミング入門
http://jats-ug.metasepi.org/doc/ATS2/INT2PROGINATS/
* ATSプログラミングチュートリアル
http://jats-ug.metasepi.org/doc/ATS2/ATS2TUTORIAL/
* Effective ATS
https://github.com/jats-ug/translate/blob/master/Manual/
EffectiveATS.md
* ATSプログラミング入門
http://jats-ug.metasepi.org/doc/ATS2/INT2PROGINATS/
* ATSプログラミングチュートリアル
http://jats-ug.metasepi.org/doc/ATS2/ATS2TUTORIAL/
* Effective ATS
https://github.com/jats-ug/translate/blob/master/Manual/
EffectiveATS.md
Join us and review it!Join us and review it!Join us and review it!Join us and review it!Join us and review it!