SlideShare a Scribd company logo
1 of 28
Download to read offline
Arduino programming of ML-
style in ATS
Arduino programming of ML-
style in ATS
Arduino programming of ML-
style in ATS
Arduino programming of ML-
style in ATS
Arduino programming of ML-
style in ATS
Kiwamu Okabe @ METASEPI
DESIGN / Hongwei Xi @ Boston
University
Kiwamu Okabe @ METASEPI
DESIGN / Hongwei Xi @ Boston
University
Kiwamu Okabe @ METASEPI
DESIGN / Hongwei Xi @ Boston
University
Kiwamu Okabe @ METASEPI
DESIGN / Hongwei Xi @ Boston
University
Kiwamu Okabe @ METASEPI
DESIGN / Hongwei Xi @ Boston
University
Demo: VideoDemo: VideoDemo: VideoDemo: VideoDemo: Video
☆ LCD greeting☆ LCD greeting☆ LCD greeting☆ LCD greeting☆ LCD greeting
☆ ⇒ http://youtu.be/5uPue0Jo1nc☆ ⇒ http://youtu.be/5uPue0Jo1nc☆ ⇒ http://youtu.be/5uPue0Jo1nc☆ ⇒ http://youtu.be/5uPue0Jo1nc☆ ⇒ http://youtu.be/5uPue0Jo1nc
☆ LED fadein☆ LED fadein☆ LED fadein☆ LED fadein☆ LED fadein
☆ ⇒ http://youtu.be/_Sx6GzuTm9k☆ ⇒ http://youtu.be/_Sx6GzuTm9k☆ ⇒ http://youtu.be/_Sx6GzuTm9k☆ ⇒ http://youtu.be/_Sx6GzuTm9k☆ ⇒ http://youtu.be/_Sx6GzuTm9k
Demo: Software ArchitectureDemo: Software ArchitectureDemo: Software ArchitectureDemo: Software ArchitectureDemo: Software Architecture
Arduino Uno hardwareArduino Uno hardwareArduino Uno hardwareArduino Uno hardwareArduino Uno hardware
It's poor.It's poor.It's poor.It's poor.It's poor.
☆ 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
Many people use C language on the
hardware.
Many people use C language on the
hardware.
Many people use C language on the
hardware.
Many people use C language on the
hardware.
Many people use C language on the
hardware.
Problem of C languageProblem of C languageProblem of C languageProblem of C languageProblem of C language
☆ Memory/Resource leak☆ Memory/Resource leak☆ Memory/Resource leak☆ Memory/Resource leak☆ Memory/Resource leak
☆ Out of bounds☆ Out of bounds☆ Out of bounds☆ Out of bounds☆ Out of bounds
☆ Weak type☆ Weak type☆ Weak type☆ Weak type☆ Weak type
We need functional language for
embedded system!
We need functional language for
embedded system!
We need functional language for
embedded system!
We need functional language for
embedded system!
We need functional language for
embedded system!
Approach 1: Virtual machineApproach 1: Virtual machineApproach 1: Virtual machineApproach 1: Virtual machineApproach 1: Virtual machine
Approach 2: DSLApproach 2: DSLApproach 2: DSLApproach 2: DSLApproach 2: DSL
Approach 3: Direct languageApproach 3: Direct languageApproach 3: Direct languageApproach 3: Direct languageApproach 3: Direct language
Comparison of the approachesComparison of the approachesComparison of the approachesComparison of the approachesComparison of the approaches
We choose the 3rd approach.We choose the 3rd approach.We choose the 3rd approach.We choose the 3rd approach.We choose the 3rd approach.
ATS languageATS languageATS languageATS languageATS language
☆ 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/
☆ 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
Author: Hongwei XiAuthor: Hongwei XiAuthor: Hongwei XiAuthor: Hongwei XiAuthor: Hongwei Xi
ATS programming levelATS programming levelATS programming levelATS programming levelATS programming level
Today, we focus on the level "c",
because Arduino hardware is poor.
Today, we focus on the level "c",
because Arduino hardware is poor.
Today, we focus on the level "c",
because Arduino hardware is poor.
Today, we focus on the level "c",
because Arduino hardware is poor.
Today, we focus on the level "c",
because Arduino hardware is poor.
Functional style programmingFunctional style programmingFunctional style programmingFunctional style programmingFunctional style programming
☆ Functional style programming can be
used with ATS on embedded system?
☆ Functional style programming can be
used with ATS on embedded system?
☆ Functional style programming can be
used with ATS on embedded system?
☆ Functional style programming can be
used with ATS on embedded system?
☆ Functional style programming can be
used with ATS on embedded system?
☆ Yes.☆ Yes.☆ Yes.☆ Yes.☆ Yes.
☆ But only use some of functional style
technique in ATS without GC and
malloc/free.
☆ But only use some of functional style
technique in ATS without GC and
malloc/free.
☆ But only use some of functional style
technique in ATS without GC and
malloc/free.
☆ But only use some of functional style
technique in ATS without GC and
malloc/free.
☆ But only use some of functional style
technique in ATS without GC and
malloc/free.
☆ Let's see some examples.☆ Let's see some examples.☆ Let's see some examples.☆ Let's see some examples.☆ Let's see some examples.
Style 1. Envless functionStyle 1. Envless functionStyle 1. Envless functionStyle 1. Envless functionStyle 1. Envless function
☆ Environment-less function.☆ Environment-less function.☆ Environment-less function.☆ Environment-less function.☆ Environment-less function.
☆ Not closure.☆ Not closure.☆ Not closure.☆ Not closure.☆ Not closure.
☆ C language function is also envless
function.
☆ C language function is also envless
function.
☆ C language function is also envless
function.
☆ C language function is also envless
function.
☆ C language function is also envless
function.
%{^ // C language code
int cfunc(int a, int b) {
return (a + b);
}
%}
// ATS language code
extern fun cfunc (a: int, b: int): int = "mac#"
implement main0 () = println! (cfunc (1, 2)) // => 3
%{^ // C language code
int cfunc(int a, int b) {
return (a + b);
}
%}
// ATS language code
extern fun cfunc (a: int, b: int): int = "mac#"
implement main0 () = println! (cfunc (1, 2)) // => 3
%{^ // C language code
int cfunc(int a, int b) {
return (a + b);
}
%}
// ATS language code
extern fun cfunc (a: int, b: int): int = "mac#"
implement main0 () = println! (cfunc (1, 2)) // => 3
%{^ // C language code
int cfunc(int a, int b) {
return (a + b);
}
%}
// ATS language code
extern fun cfunc (a: int, b: int): int = "mac#"
implement main0 () = println! (cfunc (1, 2)) // => 3
%{^ // C language code
int cfunc(int a, int b) {
return (a + b);
}
%}
// ATS language code
extern fun cfunc (a: int, b: int): int = "mac#"
implement main0 () = println! (cfunc (1, 2)) // => 3
Style 2. Stack allocated closureStyle 2. Stack allocated closureStyle 2. Stack allocated closureStyle 2. Stack allocated closureStyle 2. Stack allocated closure
Stack allocated closure is allocated on
stack. It can use free variable.
Stack allocated closure is allocated on
stack. It can use free variable.
Stack allocated closure is allocated on
stack. It can use free variable.
Stack allocated closure is allocated on
stack. It can use free variable.
Stack allocated closure is allocated on
stack. It can use free variable.
fun run (f: &int -<clo1> int): int = f 1
implement main0 () = {
val b = 2
var plus = lam@ (a: int):int => a + b
val () = println! (run plus) // => 3
}
fun run (f: &int -<clo1> int): int = f 1
implement main0 () = {
val b = 2
var plus = lam@ (a: int):int => a + b
val () = println! (run plus) // => 3
}
fun run (f: &int -<clo1> int): int = f 1
implement main0 () = {
val b = 2
var plus = lam@ (a: int):int => a + b
val () = println! (run plus) // => 3
}
fun run (f: &int -<clo1> int): int = f 1
implement main0 () = {
val b = 2
var plus = lam@ (a: int):int => a + b
val () = println! (run plus) // => 3
}
fun run (f: &int -<clo1> int): int = f 1
implement main0 () = {
val b = 2
var plus = lam@ (a: int):int => a + b
val () = println! (run plus) // => 3
}
Style 3. Template functionStyle 3. Template functionStyle 3. Template functionStyle 3. Template functionStyle 3. Template function
The template is functorial style that has
lexical scoping.
The template is functorial style that has
lexical scoping.
The template is functorial style that has
lexical scoping.
The template is functorial style that has
lexical scoping.
The template is functorial style that has
lexical scoping.
extern fun{} base (): int
fun{} plus (a: int): int = a + base ()
implement main0 () = {
implement{} base () = 2
val () = println! (plus 1) // => 3
}
extern fun{} base (): int
fun{} plus (a: int): int = a + base ()
implement main0 () = {
implement{} base () = 2
val () = println! (plus 1) // => 3
}
extern fun{} base (): int
fun{} plus (a: int): int = a + base ()
implement main0 () = {
implement{} base () = 2
val () = println! (plus 1) // => 3
}
extern fun{} base (): int
fun{} plus (a: int): int = a + base ()
implement main0 () = {
implement{} base () = 2
val () = println! (plus 1) // => 3
}
extern fun{} base (): int
fun{} plus (a: int): int = a + base ()
implement main0 () = {
implement{} base () = 2
val () = println! (plus 1) // => 3
}
Safety shaped by ATSSafety shaped by ATSSafety shaped by ATSSafety shaped by ATSSafety shaped by ATS
☆ ATS is a better C language.☆ ATS is a better C language.☆ ATS is a better C language.☆ ATS is a better C language.☆ ATS is a better C language.
☆ "Better" is meaning "Safer".☆ "Better" is meaning "Safer".☆ "Better" is meaning "Safer".☆ "Better" is meaning "Safer".☆ "Better" is meaning "Safer".
☆ Let's see some examples.☆ Let's see some examples.☆ Let's see some examples.☆ Let's see some examples.☆ Let's see some examples.
Safety 1. Termination metricsSafety 1. Termination metricsSafety 1. Termination metricsSafety 1. Termination metricsSafety 1. Termination metrics
".<255 - n>." is termination metric that
grows smaller on each recursive call,
for termination-checking.
".<255 - n>." is termination metric that
grows smaller on each recursive call,
for termination-checking.
".<255 - n>." is termination metric that
grows smaller on each recursive call,
for termination-checking.
".<255 - n>." is termination metric that
grows smaller on each recursive call,
for termination-checking.
".<255 - n>." is termination metric that
grows smaller on each recursive call,
for termination-checking.
fun loop_fadein {n:nat | n <= 255} .<255 - n>. (i: int n): void = {
val () = analogWrite (LED, i)
val () = delay_ms (BLINK_DELAY_MS)
val () = if i < 255 then loop_fadein (i + 1)
}
...
val () = loop_fadein 0
fun loop_fadein {n:nat | n <= 255} .<255 - n>. (i: int n): void = {
val () = analogWrite (LED, i)
val () = delay_ms (BLINK_DELAY_MS)
val () = if i < 255 then loop_fadein (i + 1)
}
...
val () = loop_fadein 0
fun loop_fadein {n:nat | n <= 255} .<255 - n>. (i: int n): void = {
val () = analogWrite (LED, i)
val () = delay_ms (BLINK_DELAY_MS)
val () = if i < 255 then loop_fadein (i + 1)
}
...
val () = loop_fadein 0
fun loop_fadein {n:nat | n <= 255} .<255 - n>. (i: int n): void = {
val () = analogWrite (LED, i)
val () = delay_ms (BLINK_DELAY_MS)
val () = if i < 255 then loop_fadein (i + 1)
}
...
val () = loop_fadein 0
fun loop_fadein {n:nat | n <= 255} .<255 - n>. (i: int n): void = {
val () = analogWrite (LED, i)
val () = delay_ms (BLINK_DELAY_MS)
val () = if i < 255 then loop_fadein (i + 1)
}
...
val () = loop_fadein 0
Safety 2. DML dependent typesSafety 2. DML dependent typesSafety 2. DML dependent typesSafety 2. DML dependent typesSafety 2. DML dependent types
"size_t (i)" is a type that depends on
static value "i". "i" has constraint "i < n".
If the constraint is not solved, it causes
compile error.
"size_t (i)" is a type that depends on
static value "i". "i" has constraint "i < n".
If the constraint is not solved, it causes
compile error.
"size_t (i)" is a type that depends on
static value "i". "i" has constraint "i < n".
If the constraint is not solved, it causes
compile error.
"size_t (i)" is a type that depends on
static value "i". "i" has constraint "i < n".
If the constraint is not solved, it causes
compile error.
"size_t (i)" is a type that depends on
static value "i". "i" has constraint "i < n".
If the constraint is not solved, it causes
compile error.
fun lcd_print {n:int}{i:nat | i < n}{j:nat | i + j <= n}
(lcd: !lcd_t, str: string (n), start: size_t (i),
len: size_t (j)): void
fun lcd_print {n:int}{i:nat | i < n}{j:nat | i + j <= n}
(lcd: !lcd_t, str: string (n), start: size_t (i),
len: size_t (j)): void
fun lcd_print {n:int}{i:nat | i < n}{j:nat | i + j <= n}
(lcd: !lcd_t, str: string (n), start: size_t (i),
len: size_t (j)): void
fun lcd_print {n:int}{i:nat | i < n}{j:nat | i + j <= n}
(lcd: !lcd_t, str: string (n), start: size_t (i),
len: size_t (j)): void
fun lcd_print {n:int}{i:nat | i < n}{j:nat | i + j <= n}
(lcd: !lcd_t, str: string (n), start: size_t (i),
len: size_t (j)): void
Safety 3. ViewSafety 3. ViewSafety 3. ViewSafety 3. ViewSafety 3. View
Linear proofs should be produced and
consumed.
Linear proofs should be produced and
consumed.
Linear proofs should be produced and
consumed.
Linear proofs should be produced and
consumed.
Linear proofs should be produced and
consumed.
If a produced linear proof is not
consumed, it causes type error at
compile time.
If a produced linear proof is not
consumed, it causes type error at
compile time.
If a produced linear proof is not
consumed, it causes type error at
compile time.
If a produced linear proof is not
consumed, it causes type error at
compile time.
If a produced linear proof is not
consumed, it causes type error at
compile time.
// lcd.sats - Library interface
absvtype lcd_t = ptr
fun lcd_open (rs: int, rw: int, enable: int, d0: int, d1: int,
d2: int, d3: int): lcd_t // Produce linear value
fun lcd_close (lcd: lcd_t): void // Consume linear value
// main.dats - Application code
implement main () = {
val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7)
// ...Do something...
val () = lcd_close lcd // <= If not, compile error occurs.
}
// lcd.sats - Library interface
absvtype lcd_t = ptr
fun lcd_open (rs: int, rw: int, enable: int, d0: int, d1: int,
d2: int, d3: int): lcd_t // Produce linear value
fun lcd_close (lcd: lcd_t): void // Consume linear value
// main.dats - Application code
implement main () = {
val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7)
// ...Do something...
val () = lcd_close lcd // <= If not, compile error occurs.
}
// lcd.sats - Library interface
absvtype lcd_t = ptr
fun lcd_open (rs: int, rw: int, enable: int, d0: int, d1: int,
d2: int, d3: int): lcd_t // Produce linear value
fun lcd_close (lcd: lcd_t): void // Consume linear value
// main.dats - Application code
implement main () = {
val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7)
// ...Do something...
val () = lcd_close lcd // <= If not, compile error occurs.
}
// lcd.sats - Library interface
absvtype lcd_t = ptr
fun lcd_open (rs: int, rw: int, enable: int, d0: int, d1: int,
d2: int, d3: int): lcd_t // Produce linear value
fun lcd_close (lcd: lcd_t): void // Consume linear value
// main.dats - Application code
implement main () = {
val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7)
// ...Do something...
val () = lcd_close lcd // <= If not, compile error occurs.
}
// lcd.sats - Library interface
absvtype lcd_t = ptr
fun lcd_open (rs: int, rw: int, enable: int, d0: int, d1: int,
d2: int, d3: int): lcd_t // Produce linear value
fun lcd_close (lcd: lcd_t): void // Consume linear value
// main.dats - Application code
implement main () = {
val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7)
// ...Do something...
val () = lcd_close lcd // <= If not, compile error occurs.
}
Safety 4. At-viewSafety 4. At-viewSafety 4. At-viewSafety 4. At-viewSafety 4. At-view
dataview array_v (a:t@ype+, addr, int) =
| {l:addr} array_v_nil (a, l, 0)
| {l:addr}{n:nat} array_v_cons (a, l, n+1) of
(a @ l, array_v (a, l+sizeof(a), n))
dataview array_v (a:t@ype+, addr, int) =
| {l:addr} array_v_nil (a, l, 0)
| {l:addr}{n:nat} array_v_cons (a, l, n+1) of
(a @ l, array_v (a, l+sizeof(a), n))
dataview array_v (a:t@ype+, addr, int) =
| {l:addr} array_v_nil (a, l, 0)
| {l:addr}{n:nat} array_v_cons (a, l, n+1) of
(a @ l, array_v (a, l+sizeof(a), n))
dataview array_v (a:t@ype+, addr, int) =
| {l:addr} array_v_nil (a, l, 0)
| {l:addr}{n:nat} array_v_cons (a, l, n+1) of
(a @ l, array_v (a, l+sizeof(a), n))
dataview array_v (a:t@ype+, addr, int) =
| {l:addr} array_v_nil (a, l, 0)
| {l:addr}{n:nat} array_v_cons (a, l, n+1) of
(a @ l, array_v (a, l+sizeof(a), n))
Demo code: LED fadeinDemo code: LED fadeinDemo code: LED fadeinDemo code: LED fadeinDemo code: LED fadein
#define LED 9
#define DELAY_MS 10.0
typedef analog_w_t = natLt(256)
fun{} int_foreach_clo{n:nat}
(n: int(n), fwork: &natLt(n) -<clo1> void): void =
loop(0, fwork) where {
fun loop{i:nat | i <= n} .<n-i>.
(i: int(i), fwork: &natLt(n) -<clo1> void): void =
if i < n then (fwork(i); loop (i+1, fwork))
}
implement main () = {
fun fadein() = let
var fwork = lam@ (n: analog_w_t) =>
(analogWrite (LED, n); delay_ms(DELAY_MS))
in
int_foreach_clo(256, fwork)
end // end of [fadein]
val () = pinMode (LED, OUTPUT)
val () = (fix f(): void => (fadein(); f()))()
}
#define LED 9
#define DELAY_MS 10.0
typedef analog_w_t = natLt(256)
fun{} int_foreach_clo{n:nat}
(n: int(n), fwork: &natLt(n) -<clo1> void): void =
loop(0, fwork) where {
fun loop{i:nat | i <= n} .<n-i>.
(i: int(i), fwork: &natLt(n) -<clo1> void): void =
if i < n then (fwork(i); loop (i+1, fwork))
}
implement main () = {
fun fadein() = let
var fwork = lam@ (n: analog_w_t) =>
(analogWrite (LED, n); delay_ms(DELAY_MS))
in
int_foreach_clo(256, fwork)
end // end of [fadein]
val () = pinMode (LED, OUTPUT)
val () = (fix f(): void => (fadein(); f()))()
}
#define LED 9
#define DELAY_MS 10.0
typedef analog_w_t = natLt(256)
fun{} int_foreach_clo{n:nat}
(n: int(n), fwork: &natLt(n) -<clo1> void): void =
loop(0, fwork) where {
fun loop{i:nat | i <= n} .<n-i>.
(i: int(i), fwork: &natLt(n) -<clo1> void): void =
if i < n then (fwork(i); loop (i+1, fwork))
}
implement main () = {
fun fadein() = let
var fwork = lam@ (n: analog_w_t) =>
(analogWrite (LED, n); delay_ms(DELAY_MS))
in
int_foreach_clo(256, fwork)
end // end of [fadein]
val () = pinMode (LED, OUTPUT)
val () = (fix f(): void => (fadein(); f()))()
}
#define LED 9
#define DELAY_MS 10.0
typedef analog_w_t = natLt(256)
fun{} int_foreach_clo{n:nat}
(n: int(n), fwork: &natLt(n) -<clo1> void): void =
loop(0, fwork) where {
fun loop{i:nat | i <= n} .<n-i>.
(i: int(i), fwork: &natLt(n) -<clo1> void): void =
if i < n then (fwork(i); loop (i+1, fwork))
}
implement main () = {
fun fadein() = let
var fwork = lam@ (n: analog_w_t) =>
(analogWrite (LED, n); delay_ms(DELAY_MS))
in
int_foreach_clo(256, fwork)
end // end of [fadein]
val () = pinMode (LED, OUTPUT)
val () = (fix f(): void => (fadein(); f()))()
}
#define LED 9
#define DELAY_MS 10.0
typedef analog_w_t = natLt(256)
fun{} int_foreach_clo{n:nat}
(n: int(n), fwork: &natLt(n) -<clo1> void): void =
loop(0, fwork) where {
fun loop{i:nat | i <= n} .<n-i>.
(i: int(i), fwork: &natLt(n) -<clo1> void): void =
if i < n then (fwork(i); loop (i+1, fwork))
}
implement main () = {
fun fadein() = let
var fwork = lam@ (n: analog_w_t) =>
(analogWrite (LED, n); delay_ms(DELAY_MS))
in
int_foreach_clo(256, fwork)
end // end of [fadein]
val () = pinMode (LED, OUTPUT)
val () = (fix f(): void => (fadein(); f()))()
}
Demo code: LCD greeting (cont.)Demo code: LCD greeting (cont.)Demo code: LCD greeting (cont.)Demo code: LCD greeting (cont.)Demo code: LCD greeting (cont.)
#define MY_DELAY_MS 400.0
#define LCD_WIDTH 16
val g_str_atsrun = "<ATS running!>"
val g_str_message = "...Greeting message..."
implement main () = {
fun loop {n:int}{i:nat | i < n} .<n-i>.
(lcd: !lcd_t, str: string (n), pos: size_t (i)): void = {
val () = if pos + i2sz LCD_WIDTH <= length str then {
val () = lcd_setCursor (lcd, 1, 0)
val () = lcd_print (lcd, g_str_atsrun, i2sz 0,
length g_str_atsrun)
val () = lcd_setCursor (lcd, 0, 1)
val () = lcd_print (lcd, str, pos, i2sz LCD_WIDTH)
val () = delay_ms (MY_DELAY_MS)
val () = loop (lcd, str, pos + 1)
}
}
#define MY_DELAY_MS 400.0
#define LCD_WIDTH 16
val g_str_atsrun = "<ATS running!>"
val g_str_message = "...Greeting message..."
implement main () = {
fun loop {n:int}{i:nat | i < n} .<n-i>.
(lcd: !lcd_t, str: string (n), pos: size_t (i)): void = {
val () = if pos + i2sz LCD_WIDTH <= length str then {
val () = lcd_setCursor (lcd, 1, 0)
val () = lcd_print (lcd, g_str_atsrun, i2sz 0,
length g_str_atsrun)
val () = lcd_setCursor (lcd, 0, 1)
val () = lcd_print (lcd, str, pos, i2sz LCD_WIDTH)
val () = delay_ms (MY_DELAY_MS)
val () = loop (lcd, str, pos + 1)
}
}
#define MY_DELAY_MS 400.0
#define LCD_WIDTH 16
val g_str_atsrun = "<ATS running!>"
val g_str_message = "...Greeting message..."
implement main () = {
fun loop {n:int}{i:nat | i < n} .<n-i>.
(lcd: !lcd_t, str: string (n), pos: size_t (i)): void = {
val () = if pos + i2sz LCD_WIDTH <= length str then {
val () = lcd_setCursor (lcd, 1, 0)
val () = lcd_print (lcd, g_str_atsrun, i2sz 0,
length g_str_atsrun)
val () = lcd_setCursor (lcd, 0, 1)
val () = lcd_print (lcd, str, pos, i2sz LCD_WIDTH)
val () = delay_ms (MY_DELAY_MS)
val () = loop (lcd, str, pos + 1)
}
}
#define MY_DELAY_MS 400.0
#define LCD_WIDTH 16
val g_str_atsrun = "<ATS running!>"
val g_str_message = "...Greeting message..."
implement main () = {
fun loop {n:int}{i:nat | i < n} .<n-i>.
(lcd: !lcd_t, str: string (n), pos: size_t (i)): void = {
val () = if pos + i2sz LCD_WIDTH <= length str then {
val () = lcd_setCursor (lcd, 1, 0)
val () = lcd_print (lcd, g_str_atsrun, i2sz 0,
length g_str_atsrun)
val () = lcd_setCursor (lcd, 0, 1)
val () = lcd_print (lcd, str, pos, i2sz LCD_WIDTH)
val () = delay_ms (MY_DELAY_MS)
val () = loop (lcd, str, pos + 1)
}
}
#define MY_DELAY_MS 400.0
#define LCD_WIDTH 16
val g_str_atsrun = "<ATS running!>"
val g_str_message = "...Greeting message..."
implement main () = {
fun loop {n:int}{i:nat | i < n} .<n-i>.
(lcd: !lcd_t, str: string (n), pos: size_t (i)): void = {
val () = if pos + i2sz LCD_WIDTH <= length str then {
val () = lcd_setCursor (lcd, 1, 0)
val () = lcd_print (lcd, g_str_atsrun, i2sz 0,
length g_str_atsrun)
val () = lcd_setCursor (lcd, 0, 1)
val () = lcd_print (lcd, str, pos, i2sz LCD_WIDTH)
val () = delay_ms (MY_DELAY_MS)
val () = loop (lcd, str, pos + 1)
}
}
Demo code: LCD greetingDemo code: LCD greetingDemo code: LCD greetingDemo code: LCD greetingDemo code: LCD greeting
fun forever {n:int}{i:nat | i < n}
(lcd: !lcd_t, str: string (n), pos: size_t (i)):
void = {
val () = loop (lcd, str, pos)
val () = forever (lcd, str, pos)
}
val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7)
val () = forever (lcd, g_str_message, i2sz 0)
val () = lcd_close lcd
}
fun forever {n:int}{i:nat | i < n}
(lcd: !lcd_t, str: string (n), pos: size_t (i)):
void = {
val () = loop (lcd, str, pos)
val () = forever (lcd, str, pos)
}
val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7)
val () = forever (lcd, g_str_message, i2sz 0)
val () = lcd_close lcd
}
fun forever {n:int}{i:nat | i < n}
(lcd: !lcd_t, str: string (n), pos: size_t (i)):
void = {
val () = loop (lcd, str, pos)
val () = forever (lcd, str, pos)
}
val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7)
val () = forever (lcd, g_str_message, i2sz 0)
val () = lcd_close lcd
}
fun forever {n:int}{i:nat | i < n}
(lcd: !lcd_t, str: string (n), pos: size_t (i)):
void = {
val () = loop (lcd, str, pos)
val () = forever (lcd, str, pos)
}
val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7)
val () = forever (lcd, g_str_message, i2sz 0)
val () = lcd_close lcd
}
fun forever {n:int}{i:nat | i < n}
(lcd: !lcd_t, str: string (n), pos: size_t (i)):
void = {
val () = loop (lcd, str, pos)
val () = forever (lcd, str, pos)
}
val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7)
val () = forever (lcd, g_str_message, i2sz 0)
val () = lcd_close lcd
}
Binary size efficiencyBinary size efficiencyBinary size efficiencyBinary size efficiencyBinary size efficiency
For examples on "Getting Started with
Arduino", ATS has good binary size
efficiency as well as C.
For examples on "Getting Started with
Arduino", ATS has good binary size
efficiency as well as C.
For examples on "Getting Started with
Arduino", ATS has good binary size
efficiency as well as C.
For examples on "Getting Started with
Arduino", ATS has good binary size
efficiency as well as C.
For examples on "Getting Started with
Arduino", ATS has good binary size
efficiency as well as C.
ConclusionConclusionConclusionConclusionConclusion
☆ Can we directly use functional style
programming on embedded system?
☆ Can we directly use functional style
programming on embedded system?
☆ Can we directly use functional style
programming on embedded system?
☆ Can we directly use functional style
programming on embedded system?
☆ Can we directly use functional style
programming on embedded system?
☆ ⇒ Yes, with ATS language.☆ ⇒ Yes, with ATS language.☆ ⇒ Yes, with ATS language.☆ ⇒ Yes, with ATS language.☆ ⇒ Yes, with ATS language.
☆ Can we make more safety than C
language on embedded system?
☆ Can we make more safety than C
language on embedded system?
☆ Can we make more safety than C
language on embedded system?
☆ Can we make more safety than C
language on embedded system?
☆ Can we make more safety than C
language on embedded system?
☆ ⇒ Yes, with ATS language.☆ ⇒ Yes, with ATS language.☆ ⇒ Yes, with ATS language.☆ ⇒ Yes, with ATS language.☆ ⇒ Yes, with ATS language.
https://github.com/fpiot/arduino-atshttps://github.com/fpiot/arduino-atshttps://github.com/fpiot/arduino-atshttps://github.com/fpiot/arduino-atshttps://github.com/fpiot/arduino-ats
License of photos #1License of photos #1License of photos #1License of photos #1License of photos #1
* Minecraft toys | Flickr - Photo Sharing!
https://www.flickr.com/photos/sergesegal/15976451410/
Copyright: 2015 Sergey Galyonkin / License: CC BY-SA 2.0
* Arduino Uno | Flickr - Photo Sharing!
https://www.flickr.com/photos/snootlab/6052455554/
Copyright: Snootlab / License: CC BY 2.0
* Thank You Dennis Ritchie | Flickr - Photo Sharing!
https://www.flickr.com/photos/vincentpants/6239875256/
Copyright: Vincent van Haaff / License: CC BY-SA 2.0
* Climbing Journal Mount Rinjani package | Flickr - Photo Sharing!
https://www.flickr.com/photos/trekkingrinjani/4930552641/
Copyright: Trekking Rinjani / License: CC BY 2.0
* Recycling Grunge Sign | Flickr - Photo Sharing!
https://www.flickr.com/photos/80497449@N04/8677649972/
Copyright: Nicolas Raymond / License: CC BY 2.0
* IMG_4097 | Flickr - Photo Sharing!
https://www.flickr.com/photos/matthewpiatt/1562708158/
Copyright: Matthew Piatt / License: CC BY-SA 2.0
* Seagulls in Flight | Flickr - Photo Sharing!
https://www.flickr.com/photos/87007001@N04/13513835453/
Copyright: Shaun Fisher / License: CC BY 2.0
* Minecraft toys | Flickr - Photo Sharing!
https://www.flickr.com/photos/sergesegal/15976451410/
Copyright: 2015 Sergey Galyonkin / License: CC BY-SA 2.0
* Arduino Uno | Flickr - Photo Sharing!
https://www.flickr.com/photos/snootlab/6052455554/
Copyright: Snootlab / License: CC BY 2.0
* Thank You Dennis Ritchie | Flickr - Photo Sharing!
https://www.flickr.com/photos/vincentpants/6239875256/
Copyright: Vincent van Haaff / License: CC BY-SA 2.0
* Climbing Journal Mount Rinjani package | Flickr - Photo Sharing!
https://www.flickr.com/photos/trekkingrinjani/4930552641/
Copyright: Trekking Rinjani / License: CC BY 2.0
* Recycling Grunge Sign | Flickr - Photo Sharing!
https://www.flickr.com/photos/80497449@N04/8677649972/
Copyright: Nicolas Raymond / License: CC BY 2.0
* IMG_4097 | Flickr - Photo Sharing!
https://www.flickr.com/photos/matthewpiatt/1562708158/
Copyright: Matthew Piatt / License: CC BY-SA 2.0
* Seagulls in Flight | Flickr - Photo Sharing!
https://www.flickr.com/photos/87007001@N04/13513835453/
Copyright: Shaun Fisher / License: CC BY 2.0
* Minecraft toys | Flickr - Photo Sharing!
https://www.flickr.com/photos/sergesegal/15976451410/
Copyright: 2015 Sergey Galyonkin / License: CC BY-SA 2.0
* Arduino Uno | Flickr - Photo Sharing!
https://www.flickr.com/photos/snootlab/6052455554/
Copyright: Snootlab / License: CC BY 2.0
* Thank You Dennis Ritchie | Flickr - Photo Sharing!
https://www.flickr.com/photos/vincentpants/6239875256/
Copyright: Vincent van Haaff / License: CC BY-SA 2.0
* Climbing Journal Mount Rinjani package | Flickr - Photo Sharing!
https://www.flickr.com/photos/trekkingrinjani/4930552641/
Copyright: Trekking Rinjani / License: CC BY 2.0
* Recycling Grunge Sign | Flickr - Photo Sharing!
https://www.flickr.com/photos/80497449@N04/8677649972/
Copyright: Nicolas Raymond / License: CC BY 2.0
* IMG_4097 | Flickr - Photo Sharing!
https://www.flickr.com/photos/matthewpiatt/1562708158/
Copyright: Matthew Piatt / License: CC BY-SA 2.0
* Seagulls in Flight | Flickr - Photo Sharing!
https://www.flickr.com/photos/87007001@N04/13513835453/
Copyright: Shaun Fisher / License: CC BY 2.0
* Minecraft toys | Flickr - Photo Sharing!
https://www.flickr.com/photos/sergesegal/15976451410/
Copyright: 2015 Sergey Galyonkin / License: CC BY-SA 2.0
* Arduino Uno | Flickr - Photo Sharing!
https://www.flickr.com/photos/snootlab/6052455554/
Copyright: Snootlab / License: CC BY 2.0
* Thank You Dennis Ritchie | Flickr - Photo Sharing!
https://www.flickr.com/photos/vincentpants/6239875256/
Copyright: Vincent van Haaff / License: CC BY-SA 2.0
* Climbing Journal Mount Rinjani package | Flickr - Photo Sharing!
https://www.flickr.com/photos/trekkingrinjani/4930552641/
Copyright: Trekking Rinjani / License: CC BY 2.0
* Recycling Grunge Sign | Flickr - Photo Sharing!
https://www.flickr.com/photos/80497449@N04/8677649972/
Copyright: Nicolas Raymond / License: CC BY 2.0
* IMG_4097 | Flickr - Photo Sharing!
https://www.flickr.com/photos/matthewpiatt/1562708158/
Copyright: Matthew Piatt / License: CC BY-SA 2.0
* Seagulls in Flight | Flickr - Photo Sharing!
https://www.flickr.com/photos/87007001@N04/13513835453/
Copyright: Shaun Fisher / License: CC BY 2.0
* Minecraft toys | Flickr - Photo Sharing!
https://www.flickr.com/photos/sergesegal/15976451410/
Copyright: 2015 Sergey Galyonkin / License: CC BY-SA 2.0
* Arduino Uno | Flickr - Photo Sharing!
https://www.flickr.com/photos/snootlab/6052455554/
Copyright: Snootlab / License: CC BY 2.0
* Thank You Dennis Ritchie | Flickr - Photo Sharing!
https://www.flickr.com/photos/vincentpants/6239875256/
Copyright: Vincent van Haaff / License: CC BY-SA 2.0
* Climbing Journal Mount Rinjani package | Flickr - Photo Sharing!
https://www.flickr.com/photos/trekkingrinjani/4930552641/
Copyright: Trekking Rinjani / License: CC BY 2.0
* Recycling Grunge Sign | Flickr - Photo Sharing!
https://www.flickr.com/photos/80497449@N04/8677649972/
Copyright: Nicolas Raymond / License: CC BY 2.0
* IMG_4097 | Flickr - Photo Sharing!
https://www.flickr.com/photos/matthewpiatt/1562708158/
Copyright: Matthew Piatt / License: CC BY-SA 2.0
* Seagulls in Flight | Flickr - Photo Sharing!
https://www.flickr.com/photos/87007001@N04/13513835453/
Copyright: Shaun Fisher / License: CC BY 2.0
License of photos #2License of photos #2License of photos #2License of photos #2License of photos #2
* Arduino Uno unboxing | Flickr - Photo Sharing!
https://www.flickr.com/photos/mightyohm/5052594028/
Copyright: Jeff Keyzer / License: CC BY-SA 2.0
* Creative Commons BBB | Flickr - Photo Sharing!
https://www.flickr.com/photos/steren/2732488224/
Copyright: Steren Giannini / License: CC BY 2.0
* LED | Flickr - Photo Sharing!
https://www.flickr.com/photos/nao904/6084536885/
Copyright: Nao. Fujita / License: CC BY 2.0
* Pagoda's curly steps | Flickr - Photo Sharing!
https://www.flickr.com/photos/kewl/6834141860/
Copyright: Tristan Schmurr / License: CC BY 2.0
* Arduino Uno unboxing | Flickr - Photo Sharing!
https://www.flickr.com/photos/mightyohm/5052594028/
Copyright: Jeff Keyzer / License: CC BY-SA 2.0
* Creative Commons BBB | Flickr - Photo Sharing!
https://www.flickr.com/photos/steren/2732488224/
Copyright: Steren Giannini / License: CC BY 2.0
* LED | Flickr - Photo Sharing!
https://www.flickr.com/photos/nao904/6084536885/
Copyright: Nao. Fujita / License: CC BY 2.0
* Pagoda's curly steps | Flickr - Photo Sharing!
https://www.flickr.com/photos/kewl/6834141860/
Copyright: Tristan Schmurr / License: CC BY 2.0
* Arduino Uno unboxing | Flickr - Photo Sharing!
https://www.flickr.com/photos/mightyohm/5052594028/
Copyright: Jeff Keyzer / License: CC BY-SA 2.0
* Creative Commons BBB | Flickr - Photo Sharing!
https://www.flickr.com/photos/steren/2732488224/
Copyright: Steren Giannini / License: CC BY 2.0
* LED | Flickr - Photo Sharing!
https://www.flickr.com/photos/nao904/6084536885/
Copyright: Nao. Fujita / License: CC BY 2.0
* Pagoda's curly steps | Flickr - Photo Sharing!
https://www.flickr.com/photos/kewl/6834141860/
Copyright: Tristan Schmurr / License: CC BY 2.0
* Arduino Uno unboxing | Flickr - Photo Sharing!
https://www.flickr.com/photos/mightyohm/5052594028/
Copyright: Jeff Keyzer / License: CC BY-SA 2.0
* Creative Commons BBB | Flickr - Photo Sharing!
https://www.flickr.com/photos/steren/2732488224/
Copyright: Steren Giannini / License: CC BY 2.0
* LED | Flickr - Photo Sharing!
https://www.flickr.com/photos/nao904/6084536885/
Copyright: Nao. Fujita / License: CC BY 2.0
* Pagoda's curly steps | Flickr - Photo Sharing!
https://www.flickr.com/photos/kewl/6834141860/
Copyright: Tristan Schmurr / License: CC BY 2.0
* Arduino Uno unboxing | Flickr - Photo Sharing!
https://www.flickr.com/photos/mightyohm/5052594028/
Copyright: Jeff Keyzer / License: CC BY-SA 2.0
* Creative Commons BBB | Flickr - Photo Sharing!
https://www.flickr.com/photos/steren/2732488224/
Copyright: Steren Giannini / License: CC BY 2.0
* LED | Flickr - Photo Sharing!
https://www.flickr.com/photos/nao904/6084536885/
Copyright: Nao. Fujita / License: CC BY 2.0
* Pagoda's curly steps | Flickr - Photo Sharing!
https://www.flickr.com/photos/kewl/6834141860/
Copyright: Tristan Schmurr / License: CC BY 2.0

More Related Content

What's hot

What's hot (20)

Embedded application designed by ATS language
Embedded application designed by ATS languageEmbedded application designed by ATS language
Embedded application designed by ATS language
 
Metasepi team meeting #19: ATS application on Arduino
Metasepi team meeting #19: ATS application on ArduinoMetasepi team meeting #19: ATS application on Arduino
Metasepi team meeting #19: ATS application on Arduino
 
ATS Programming Tutorial
ATS Programming TutorialATS Programming Tutorial
ATS Programming Tutorial
 
Functional IoT: Hardware and Platform
Functional IoT: Hardware and PlatformFunctional IoT: Hardware and Platform
Functional IoT: Hardware and Platform
 
ATS programming on ESP8266
ATS programming on ESP8266ATS programming on ESP8266
ATS programming on ESP8266
 
Functional IoT: Programming Language and OS
Functional IoT: Programming Language and OSFunctional IoT: Programming Language and OS
Functional IoT: Programming Language and OS
 
Functional IoT: Introduction
Functional IoT: IntroductionFunctional IoT: Introduction
Functional IoT: Introduction
 
ATS2 updates 2017
ATS2 updates 2017ATS2 updates 2017
ATS2 updates 2017
 
Past and today of Metasepi project
Past and today of Metasepi projectPast and today of Metasepi project
Past and today of Metasepi project
 
Dear compiler please don't be my nanny v2
Dear compiler  please don't be my nanny v2Dear compiler  please don't be my nanny v2
Dear compiler please don't be my nanny v2
 
Spring, CDI, Jakarta EE good parts
Spring, CDI, Jakarta EE good partsSpring, CDI, Jakarta EE good parts
Spring, CDI, Jakarta EE good parts
 
Perl Moderno
Perl ModernoPerl Moderno
Perl Moderno
 
Make Your Own Perl with Moops
Make Your Own Perl with MoopsMake Your Own Perl with Moops
Make Your Own Perl with Moops
 
Bash is not a second zone citizen programming language
Bash is not a second zone citizen programming languageBash is not a second zone citizen programming language
Bash is not a second zone citizen programming language
 
Be pinched by a cRUSTacean to prevent programming errors !
Be pinched by a cRUSTacean to prevent programming errors !Be pinched by a cRUSTacean to prevent programming errors !
Be pinched by a cRUSTacean to prevent programming errors !
 
Final field semantics
Final field semanticsFinal field semantics
Final field semantics
 
The Perl API for the Mortally Terrified (beta)
The Perl API for the Mortally Terrified (beta)The Perl API for the Mortally Terrified (beta)
The Perl API for the Mortally Terrified (beta)
 
Reading Other Peoples Code (Web Rebels 2018)
Reading Other Peoples Code (Web Rebels 2018)Reading Other Peoples Code (Web Rebels 2018)
Reading Other Peoples Code (Web Rebels 2018)
 
What's new in Perl 5.10?
What's new in Perl 5.10?What's new in Perl 5.10?
What's new in Perl 5.10?
 
Managing a R&D Lab with Foreman
Managing a R&D Lab with ForemanManaging a R&D Lab with Foreman
Managing a R&D Lab with Foreman
 

Similar to Arduino programming of ML-style in ATS

ooc - A hybrid language experiment
ooc - A hybrid language experimentooc - A hybrid language experiment
ooc - A hybrid language experiment
Amos Wenger
 
Falcon初印象
Falcon初印象Falcon初印象
Falcon初印象
勇浩 赖
 
Programming with Java: the Basics
Programming with Java: the BasicsProgramming with Java: the Basics
Programming with Java: the Basics
Jussi Pohjolainen
 

Similar to Arduino programming of ML-style in ATS (20)

About Go
About GoAbout Go
About Go
 
(Slightly) Smarter Smart Pointers
(Slightly) Smarter Smart Pointers(Slightly) Smarter Smart Pointers
(Slightly) Smarter Smart Pointers
 
Talk About Performance
Talk About PerformanceTalk About Performance
Talk About Performance
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf Edition
 
ooc - A hybrid language experiment
ooc - A hybrid language experimentooc - A hybrid language experiment
ooc - A hybrid language experiment
 
ooc - A hybrid language experiment
ooc - A hybrid language experimentooc - A hybrid language experiment
ooc - A hybrid language experiment
 
Replace OutputIterator and Extend Range
Replace OutputIterator and Extend RangeReplace OutputIterator and Extend Range
Replace OutputIterator and Extend Range
 
Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#
 
Python 3000
Python 3000Python 3000
Python 3000
 
Java 8: the good parts!
Java 8: the good parts!Java 8: the good parts!
Java 8: the good parts!
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good Parts
 
Automate Yo' Self
Automate Yo' SelfAutomate Yo' Self
Automate Yo' Self
 
Introduction to Compiler Development
Introduction to Compiler DevelopmentIntroduction to Compiler Development
Introduction to Compiler Development
 
Falcon初印象
Falcon初印象Falcon初印象
Falcon初印象
 
The present and the future of functional programming in c++
The present and the future of functional programming in c++The present and the future of functional programming in c++
The present and the future of functional programming in c++
 
WebSummit 2015 - Gopher it
WebSummit 2015 - Gopher itWebSummit 2015 - Gopher it
WebSummit 2015 - Gopher it
 
Cranking Floating Point Performance Up To 11
Cranking Floating Point Performance Up To 11Cranking Floating Point Performance Up To 11
Cranking Floating Point Performance Up To 11
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
 
Cbasic
CbasicCbasic
Cbasic
 
Programming with Java: the Basics
Programming with Java: the BasicsProgramming with Java: the Basics
Programming with Java: the Basics
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Recently uploaded (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Arduino programming of ML-style in ATS

  • 1. Arduino programming of ML- style in ATS Arduino programming of ML- style in ATS Arduino programming of ML- style in ATS Arduino programming of ML- style in ATS Arduino programming of ML- style in ATS Kiwamu Okabe @ METASEPI DESIGN / Hongwei Xi @ Boston University Kiwamu Okabe @ METASEPI DESIGN / Hongwei Xi @ Boston University Kiwamu Okabe @ METASEPI DESIGN / Hongwei Xi @ Boston University Kiwamu Okabe @ METASEPI DESIGN / Hongwei Xi @ Boston University Kiwamu Okabe @ METASEPI DESIGN / Hongwei Xi @ Boston University
  • 2. Demo: VideoDemo: VideoDemo: VideoDemo: VideoDemo: Video ☆ LCD greeting☆ LCD greeting☆ LCD greeting☆ LCD greeting☆ LCD greeting ☆ ⇒ http://youtu.be/5uPue0Jo1nc☆ ⇒ http://youtu.be/5uPue0Jo1nc☆ ⇒ http://youtu.be/5uPue0Jo1nc☆ ⇒ http://youtu.be/5uPue0Jo1nc☆ ⇒ http://youtu.be/5uPue0Jo1nc ☆ LED fadein☆ LED fadein☆ LED fadein☆ LED fadein☆ LED fadein ☆ ⇒ http://youtu.be/_Sx6GzuTm9k☆ ⇒ http://youtu.be/_Sx6GzuTm9k☆ ⇒ http://youtu.be/_Sx6GzuTm9k☆ ⇒ http://youtu.be/_Sx6GzuTm9k☆ ⇒ http://youtu.be/_Sx6GzuTm9k
  • 3. Demo: Software ArchitectureDemo: Software ArchitectureDemo: Software ArchitectureDemo: Software ArchitectureDemo: Software Architecture
  • 4. Arduino Uno hardwareArduino Uno hardwareArduino Uno hardwareArduino Uno hardwareArduino Uno hardware It's poor.It's poor.It's poor.It's poor.It's poor. ☆ 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 Many people use C language on the hardware. Many people use C language on the hardware. Many people use C language on the hardware. Many people use C language on the hardware. Many people use C language on the hardware.
  • 5. Problem of C languageProblem of C languageProblem of C languageProblem of C languageProblem of C language ☆ Memory/Resource leak☆ Memory/Resource leak☆ Memory/Resource leak☆ Memory/Resource leak☆ Memory/Resource leak ☆ Out of bounds☆ Out of bounds☆ Out of bounds☆ Out of bounds☆ Out of bounds ☆ Weak type☆ Weak type☆ Weak type☆ Weak type☆ Weak type We need functional language for embedded system! We need functional language for embedded system! We need functional language for embedded system! We need functional language for embedded system! We need functional language for embedded system!
  • 6. Approach 1: Virtual machineApproach 1: Virtual machineApproach 1: Virtual machineApproach 1: Virtual machineApproach 1: Virtual machine
  • 7. Approach 2: DSLApproach 2: DSLApproach 2: DSLApproach 2: DSLApproach 2: DSL
  • 8. Approach 3: Direct languageApproach 3: Direct languageApproach 3: Direct languageApproach 3: Direct languageApproach 3: Direct language
  • 9. Comparison of the approachesComparison of the approachesComparison of the approachesComparison of the approachesComparison of the approaches We choose the 3rd approach.We choose the 3rd approach.We choose the 3rd approach.We choose the 3rd approach.We choose the 3rd approach.
  • 10. ATS languageATS languageATS languageATS languageATS language ☆ 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/ ☆ 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
  • 11. Author: Hongwei XiAuthor: Hongwei XiAuthor: Hongwei XiAuthor: Hongwei XiAuthor: Hongwei Xi
  • 12. ATS programming levelATS programming levelATS programming levelATS programming levelATS programming level Today, we focus on the level "c", because Arduino hardware is poor. Today, we focus on the level "c", because Arduino hardware is poor. Today, we focus on the level "c", because Arduino hardware is poor. Today, we focus on the level "c", because Arduino hardware is poor. Today, we focus on the level "c", because Arduino hardware is poor.
  • 13. Functional style programmingFunctional style programmingFunctional style programmingFunctional style programmingFunctional style programming ☆ Functional style programming can be used with ATS on embedded system? ☆ Functional style programming can be used with ATS on embedded system? ☆ Functional style programming can be used with ATS on embedded system? ☆ Functional style programming can be used with ATS on embedded system? ☆ Functional style programming can be used with ATS on embedded system? ☆ Yes.☆ Yes.☆ Yes.☆ Yes.☆ Yes. ☆ But only use some of functional style technique in ATS without GC and malloc/free. ☆ But only use some of functional style technique in ATS without GC and malloc/free. ☆ But only use some of functional style technique in ATS without GC and malloc/free. ☆ But only use some of functional style technique in ATS without GC and malloc/free. ☆ But only use some of functional style technique in ATS without GC and malloc/free. ☆ Let's see some examples.☆ Let's see some examples.☆ Let's see some examples.☆ Let's see some examples.☆ Let's see some examples.
  • 14. Style 1. Envless functionStyle 1. Envless functionStyle 1. Envless functionStyle 1. Envless functionStyle 1. Envless function ☆ Environment-less function.☆ Environment-less function.☆ Environment-less function.☆ Environment-less function.☆ Environment-less function. ☆ Not closure.☆ Not closure.☆ Not closure.☆ Not closure.☆ Not closure. ☆ C language function is also envless function. ☆ C language function is also envless function. ☆ C language function is also envless function. ☆ C language function is also envless function. ☆ C language function is also envless function. %{^ // C language code int cfunc(int a, int b) { return (a + b); } %} // ATS language code extern fun cfunc (a: int, b: int): int = "mac#" implement main0 () = println! (cfunc (1, 2)) // => 3 %{^ // C language code int cfunc(int a, int b) { return (a + b); } %} // ATS language code extern fun cfunc (a: int, b: int): int = "mac#" implement main0 () = println! (cfunc (1, 2)) // => 3 %{^ // C language code int cfunc(int a, int b) { return (a + b); } %} // ATS language code extern fun cfunc (a: int, b: int): int = "mac#" implement main0 () = println! (cfunc (1, 2)) // => 3 %{^ // C language code int cfunc(int a, int b) { return (a + b); } %} // ATS language code extern fun cfunc (a: int, b: int): int = "mac#" implement main0 () = println! (cfunc (1, 2)) // => 3 %{^ // C language code int cfunc(int a, int b) { return (a + b); } %} // ATS language code extern fun cfunc (a: int, b: int): int = "mac#" implement main0 () = println! (cfunc (1, 2)) // => 3
  • 15. Style 2. Stack allocated closureStyle 2. Stack allocated closureStyle 2. Stack allocated closureStyle 2. Stack allocated closureStyle 2. Stack allocated closure Stack allocated closure is allocated on stack. It can use free variable. Stack allocated closure is allocated on stack. It can use free variable. Stack allocated closure is allocated on stack. It can use free variable. Stack allocated closure is allocated on stack. It can use free variable. Stack allocated closure is allocated on stack. It can use free variable. fun run (f: &int -<clo1> int): int = f 1 implement main0 () = { val b = 2 var plus = lam@ (a: int):int => a + b val () = println! (run plus) // => 3 } fun run (f: &int -<clo1> int): int = f 1 implement main0 () = { val b = 2 var plus = lam@ (a: int):int => a + b val () = println! (run plus) // => 3 } fun run (f: &int -<clo1> int): int = f 1 implement main0 () = { val b = 2 var plus = lam@ (a: int):int => a + b val () = println! (run plus) // => 3 } fun run (f: &int -<clo1> int): int = f 1 implement main0 () = { val b = 2 var plus = lam@ (a: int):int => a + b val () = println! (run plus) // => 3 } fun run (f: &int -<clo1> int): int = f 1 implement main0 () = { val b = 2 var plus = lam@ (a: int):int => a + b val () = println! (run plus) // => 3 }
  • 16. Style 3. Template functionStyle 3. Template functionStyle 3. Template functionStyle 3. Template functionStyle 3. Template function The template is functorial style that has lexical scoping. The template is functorial style that has lexical scoping. The template is functorial style that has lexical scoping. The template is functorial style that has lexical scoping. The template is functorial style that has lexical scoping. extern fun{} base (): int fun{} plus (a: int): int = a + base () implement main0 () = { implement{} base () = 2 val () = println! (plus 1) // => 3 } extern fun{} base (): int fun{} plus (a: int): int = a + base () implement main0 () = { implement{} base () = 2 val () = println! (plus 1) // => 3 } extern fun{} base (): int fun{} plus (a: int): int = a + base () implement main0 () = { implement{} base () = 2 val () = println! (plus 1) // => 3 } extern fun{} base (): int fun{} plus (a: int): int = a + base () implement main0 () = { implement{} base () = 2 val () = println! (plus 1) // => 3 } extern fun{} base (): int fun{} plus (a: int): int = a + base () implement main0 () = { implement{} base () = 2 val () = println! (plus 1) // => 3 }
  • 17. Safety shaped by ATSSafety shaped by ATSSafety shaped by ATSSafety shaped by ATSSafety shaped by ATS ☆ ATS is a better C language.☆ ATS is a better C language.☆ ATS is a better C language.☆ ATS is a better C language.☆ ATS is a better C language. ☆ "Better" is meaning "Safer".☆ "Better" is meaning "Safer".☆ "Better" is meaning "Safer".☆ "Better" is meaning "Safer".☆ "Better" is meaning "Safer". ☆ Let's see some examples.☆ Let's see some examples.☆ Let's see some examples.☆ Let's see some examples.☆ Let's see some examples.
  • 18. Safety 1. Termination metricsSafety 1. Termination metricsSafety 1. Termination metricsSafety 1. Termination metricsSafety 1. Termination metrics ".<255 - n>." is termination metric that grows smaller on each recursive call, for termination-checking. ".<255 - n>." is termination metric that grows smaller on each recursive call, for termination-checking. ".<255 - n>." is termination metric that grows smaller on each recursive call, for termination-checking. ".<255 - n>." is termination metric that grows smaller on each recursive call, for termination-checking. ".<255 - n>." is termination metric that grows smaller on each recursive call, for termination-checking. fun loop_fadein {n:nat | n <= 255} .<255 - n>. (i: int n): void = { val () = analogWrite (LED, i) val () = delay_ms (BLINK_DELAY_MS) val () = if i < 255 then loop_fadein (i + 1) } ... val () = loop_fadein 0 fun loop_fadein {n:nat | n <= 255} .<255 - n>. (i: int n): void = { val () = analogWrite (LED, i) val () = delay_ms (BLINK_DELAY_MS) val () = if i < 255 then loop_fadein (i + 1) } ... val () = loop_fadein 0 fun loop_fadein {n:nat | n <= 255} .<255 - n>. (i: int n): void = { val () = analogWrite (LED, i) val () = delay_ms (BLINK_DELAY_MS) val () = if i < 255 then loop_fadein (i + 1) } ... val () = loop_fadein 0 fun loop_fadein {n:nat | n <= 255} .<255 - n>. (i: int n): void = { val () = analogWrite (LED, i) val () = delay_ms (BLINK_DELAY_MS) val () = if i < 255 then loop_fadein (i + 1) } ... val () = loop_fadein 0 fun loop_fadein {n:nat | n <= 255} .<255 - n>. (i: int n): void = { val () = analogWrite (LED, i) val () = delay_ms (BLINK_DELAY_MS) val () = if i < 255 then loop_fadein (i + 1) } ... val () = loop_fadein 0
  • 19. Safety 2. DML dependent typesSafety 2. DML dependent typesSafety 2. DML dependent typesSafety 2. DML dependent typesSafety 2. DML dependent types "size_t (i)" is a type that depends on static value "i". "i" has constraint "i < n". If the constraint is not solved, it causes compile error. "size_t (i)" is a type that depends on static value "i". "i" has constraint "i < n". If the constraint is not solved, it causes compile error. "size_t (i)" is a type that depends on static value "i". "i" has constraint "i < n". If the constraint is not solved, it causes compile error. "size_t (i)" is a type that depends on static value "i". "i" has constraint "i < n". If the constraint is not solved, it causes compile error. "size_t (i)" is a type that depends on static value "i". "i" has constraint "i < n". If the constraint is not solved, it causes compile error. fun lcd_print {n:int}{i:nat | i < n}{j:nat | i + j <= n} (lcd: !lcd_t, str: string (n), start: size_t (i), len: size_t (j)): void fun lcd_print {n:int}{i:nat | i < n}{j:nat | i + j <= n} (lcd: !lcd_t, str: string (n), start: size_t (i), len: size_t (j)): void fun lcd_print {n:int}{i:nat | i < n}{j:nat | i + j <= n} (lcd: !lcd_t, str: string (n), start: size_t (i), len: size_t (j)): void fun lcd_print {n:int}{i:nat | i < n}{j:nat | i + j <= n} (lcd: !lcd_t, str: string (n), start: size_t (i), len: size_t (j)): void fun lcd_print {n:int}{i:nat | i < n}{j:nat | i + j <= n} (lcd: !lcd_t, str: string (n), start: size_t (i), len: size_t (j)): void
  • 20. Safety 3. ViewSafety 3. ViewSafety 3. ViewSafety 3. ViewSafety 3. View Linear proofs should be produced and consumed. Linear proofs should be produced and consumed. Linear proofs should be produced and consumed. Linear proofs should be produced and consumed. Linear proofs should be produced and consumed. If a produced linear proof is not consumed, it causes type error at compile time. If a produced linear proof is not consumed, it causes type error at compile time. If a produced linear proof is not consumed, it causes type error at compile time. If a produced linear proof is not consumed, it causes type error at compile time. If a produced linear proof is not consumed, it causes type error at compile time. // lcd.sats - Library interface absvtype lcd_t = ptr fun lcd_open (rs: int, rw: int, enable: int, d0: int, d1: int, d2: int, d3: int): lcd_t // Produce linear value fun lcd_close (lcd: lcd_t): void // Consume linear value // main.dats - Application code implement main () = { val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7) // ...Do something... val () = lcd_close lcd // <= If not, compile error occurs. } // lcd.sats - Library interface absvtype lcd_t = ptr fun lcd_open (rs: int, rw: int, enable: int, d0: int, d1: int, d2: int, d3: int): lcd_t // Produce linear value fun lcd_close (lcd: lcd_t): void // Consume linear value // main.dats - Application code implement main () = { val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7) // ...Do something... val () = lcd_close lcd // <= If not, compile error occurs. } // lcd.sats - Library interface absvtype lcd_t = ptr fun lcd_open (rs: int, rw: int, enable: int, d0: int, d1: int, d2: int, d3: int): lcd_t // Produce linear value fun lcd_close (lcd: lcd_t): void // Consume linear value // main.dats - Application code implement main () = { val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7) // ...Do something... val () = lcd_close lcd // <= If not, compile error occurs. } // lcd.sats - Library interface absvtype lcd_t = ptr fun lcd_open (rs: int, rw: int, enable: int, d0: int, d1: int, d2: int, d3: int): lcd_t // Produce linear value fun lcd_close (lcd: lcd_t): void // Consume linear value // main.dats - Application code implement main () = { val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7) // ...Do something... val () = lcd_close lcd // <= If not, compile error occurs. } // lcd.sats - Library interface absvtype lcd_t = ptr fun lcd_open (rs: int, rw: int, enable: int, d0: int, d1: int, d2: int, d3: int): lcd_t // Produce linear value fun lcd_close (lcd: lcd_t): void // Consume linear value // main.dats - Application code implement main () = { val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7) // ...Do something... val () = lcd_close lcd // <= If not, compile error occurs. }
  • 21. Safety 4. At-viewSafety 4. At-viewSafety 4. At-viewSafety 4. At-viewSafety 4. At-view dataview array_v (a:t@ype+, addr, int) = | {l:addr} array_v_nil (a, l, 0) | {l:addr}{n:nat} array_v_cons (a, l, n+1) of (a @ l, array_v (a, l+sizeof(a), n)) dataview array_v (a:t@ype+, addr, int) = | {l:addr} array_v_nil (a, l, 0) | {l:addr}{n:nat} array_v_cons (a, l, n+1) of (a @ l, array_v (a, l+sizeof(a), n)) dataview array_v (a:t@ype+, addr, int) = | {l:addr} array_v_nil (a, l, 0) | {l:addr}{n:nat} array_v_cons (a, l, n+1) of (a @ l, array_v (a, l+sizeof(a), n)) dataview array_v (a:t@ype+, addr, int) = | {l:addr} array_v_nil (a, l, 0) | {l:addr}{n:nat} array_v_cons (a, l, n+1) of (a @ l, array_v (a, l+sizeof(a), n)) dataview array_v (a:t@ype+, addr, int) = | {l:addr} array_v_nil (a, l, 0) | {l:addr}{n:nat} array_v_cons (a, l, n+1) of (a @ l, array_v (a, l+sizeof(a), n))
  • 22. Demo code: LED fadeinDemo code: LED fadeinDemo code: LED fadeinDemo code: LED fadeinDemo code: LED fadein #define LED 9 #define DELAY_MS 10.0 typedef analog_w_t = natLt(256) fun{} int_foreach_clo{n:nat} (n: int(n), fwork: &natLt(n) -<clo1> void): void = loop(0, fwork) where { fun loop{i:nat | i <= n} .<n-i>. (i: int(i), fwork: &natLt(n) -<clo1> void): void = if i < n then (fwork(i); loop (i+1, fwork)) } implement main () = { fun fadein() = let var fwork = lam@ (n: analog_w_t) => (analogWrite (LED, n); delay_ms(DELAY_MS)) in int_foreach_clo(256, fwork) end // end of [fadein] val () = pinMode (LED, OUTPUT) val () = (fix f(): void => (fadein(); f()))() } #define LED 9 #define DELAY_MS 10.0 typedef analog_w_t = natLt(256) fun{} int_foreach_clo{n:nat} (n: int(n), fwork: &natLt(n) -<clo1> void): void = loop(0, fwork) where { fun loop{i:nat | i <= n} .<n-i>. (i: int(i), fwork: &natLt(n) -<clo1> void): void = if i < n then (fwork(i); loop (i+1, fwork)) } implement main () = { fun fadein() = let var fwork = lam@ (n: analog_w_t) => (analogWrite (LED, n); delay_ms(DELAY_MS)) in int_foreach_clo(256, fwork) end // end of [fadein] val () = pinMode (LED, OUTPUT) val () = (fix f(): void => (fadein(); f()))() } #define LED 9 #define DELAY_MS 10.0 typedef analog_w_t = natLt(256) fun{} int_foreach_clo{n:nat} (n: int(n), fwork: &natLt(n) -<clo1> void): void = loop(0, fwork) where { fun loop{i:nat | i <= n} .<n-i>. (i: int(i), fwork: &natLt(n) -<clo1> void): void = if i < n then (fwork(i); loop (i+1, fwork)) } implement main () = { fun fadein() = let var fwork = lam@ (n: analog_w_t) => (analogWrite (LED, n); delay_ms(DELAY_MS)) in int_foreach_clo(256, fwork) end // end of [fadein] val () = pinMode (LED, OUTPUT) val () = (fix f(): void => (fadein(); f()))() } #define LED 9 #define DELAY_MS 10.0 typedef analog_w_t = natLt(256) fun{} int_foreach_clo{n:nat} (n: int(n), fwork: &natLt(n) -<clo1> void): void = loop(0, fwork) where { fun loop{i:nat | i <= n} .<n-i>. (i: int(i), fwork: &natLt(n) -<clo1> void): void = if i < n then (fwork(i); loop (i+1, fwork)) } implement main () = { fun fadein() = let var fwork = lam@ (n: analog_w_t) => (analogWrite (LED, n); delay_ms(DELAY_MS)) in int_foreach_clo(256, fwork) end // end of [fadein] val () = pinMode (LED, OUTPUT) val () = (fix f(): void => (fadein(); f()))() } #define LED 9 #define DELAY_MS 10.0 typedef analog_w_t = natLt(256) fun{} int_foreach_clo{n:nat} (n: int(n), fwork: &natLt(n) -<clo1> void): void = loop(0, fwork) where { fun loop{i:nat | i <= n} .<n-i>. (i: int(i), fwork: &natLt(n) -<clo1> void): void = if i < n then (fwork(i); loop (i+1, fwork)) } implement main () = { fun fadein() = let var fwork = lam@ (n: analog_w_t) => (analogWrite (LED, n); delay_ms(DELAY_MS)) in int_foreach_clo(256, fwork) end // end of [fadein] val () = pinMode (LED, OUTPUT) val () = (fix f(): void => (fadein(); f()))() }
  • 23. Demo code: LCD greeting (cont.)Demo code: LCD greeting (cont.)Demo code: LCD greeting (cont.)Demo code: LCD greeting (cont.)Demo code: LCD greeting (cont.) #define MY_DELAY_MS 400.0 #define LCD_WIDTH 16 val g_str_atsrun = "<ATS running!>" val g_str_message = "...Greeting message..." implement main () = { fun loop {n:int}{i:nat | i < n} .<n-i>. (lcd: !lcd_t, str: string (n), pos: size_t (i)): void = { val () = if pos + i2sz LCD_WIDTH <= length str then { val () = lcd_setCursor (lcd, 1, 0) val () = lcd_print (lcd, g_str_atsrun, i2sz 0, length g_str_atsrun) val () = lcd_setCursor (lcd, 0, 1) val () = lcd_print (lcd, str, pos, i2sz LCD_WIDTH) val () = delay_ms (MY_DELAY_MS) val () = loop (lcd, str, pos + 1) } } #define MY_DELAY_MS 400.0 #define LCD_WIDTH 16 val g_str_atsrun = "<ATS running!>" val g_str_message = "...Greeting message..." implement main () = { fun loop {n:int}{i:nat | i < n} .<n-i>. (lcd: !lcd_t, str: string (n), pos: size_t (i)): void = { val () = if pos + i2sz LCD_WIDTH <= length str then { val () = lcd_setCursor (lcd, 1, 0) val () = lcd_print (lcd, g_str_atsrun, i2sz 0, length g_str_atsrun) val () = lcd_setCursor (lcd, 0, 1) val () = lcd_print (lcd, str, pos, i2sz LCD_WIDTH) val () = delay_ms (MY_DELAY_MS) val () = loop (lcd, str, pos + 1) } } #define MY_DELAY_MS 400.0 #define LCD_WIDTH 16 val g_str_atsrun = "<ATS running!>" val g_str_message = "...Greeting message..." implement main () = { fun loop {n:int}{i:nat | i < n} .<n-i>. (lcd: !lcd_t, str: string (n), pos: size_t (i)): void = { val () = if pos + i2sz LCD_WIDTH <= length str then { val () = lcd_setCursor (lcd, 1, 0) val () = lcd_print (lcd, g_str_atsrun, i2sz 0, length g_str_atsrun) val () = lcd_setCursor (lcd, 0, 1) val () = lcd_print (lcd, str, pos, i2sz LCD_WIDTH) val () = delay_ms (MY_DELAY_MS) val () = loop (lcd, str, pos + 1) } } #define MY_DELAY_MS 400.0 #define LCD_WIDTH 16 val g_str_atsrun = "<ATS running!>" val g_str_message = "...Greeting message..." implement main () = { fun loop {n:int}{i:nat | i < n} .<n-i>. (lcd: !lcd_t, str: string (n), pos: size_t (i)): void = { val () = if pos + i2sz LCD_WIDTH <= length str then { val () = lcd_setCursor (lcd, 1, 0) val () = lcd_print (lcd, g_str_atsrun, i2sz 0, length g_str_atsrun) val () = lcd_setCursor (lcd, 0, 1) val () = lcd_print (lcd, str, pos, i2sz LCD_WIDTH) val () = delay_ms (MY_DELAY_MS) val () = loop (lcd, str, pos + 1) } } #define MY_DELAY_MS 400.0 #define LCD_WIDTH 16 val g_str_atsrun = "<ATS running!>" val g_str_message = "...Greeting message..." implement main () = { fun loop {n:int}{i:nat | i < n} .<n-i>. (lcd: !lcd_t, str: string (n), pos: size_t (i)): void = { val () = if pos + i2sz LCD_WIDTH <= length str then { val () = lcd_setCursor (lcd, 1, 0) val () = lcd_print (lcd, g_str_atsrun, i2sz 0, length g_str_atsrun) val () = lcd_setCursor (lcd, 0, 1) val () = lcd_print (lcd, str, pos, i2sz LCD_WIDTH) val () = delay_ms (MY_DELAY_MS) val () = loop (lcd, str, pos + 1) } }
  • 24. Demo code: LCD greetingDemo code: LCD greetingDemo code: LCD greetingDemo code: LCD greetingDemo code: LCD greeting fun forever {n:int}{i:nat | i < n} (lcd: !lcd_t, str: string (n), pos: size_t (i)): void = { val () = loop (lcd, str, pos) val () = forever (lcd, str, pos) } val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7) val () = forever (lcd, g_str_message, i2sz 0) val () = lcd_close lcd } fun forever {n:int}{i:nat | i < n} (lcd: !lcd_t, str: string (n), pos: size_t (i)): void = { val () = loop (lcd, str, pos) val () = forever (lcd, str, pos) } val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7) val () = forever (lcd, g_str_message, i2sz 0) val () = lcd_close lcd } fun forever {n:int}{i:nat | i < n} (lcd: !lcd_t, str: string (n), pos: size_t (i)): void = { val () = loop (lcd, str, pos) val () = forever (lcd, str, pos) } val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7) val () = forever (lcd, g_str_message, i2sz 0) val () = lcd_close lcd } fun forever {n:int}{i:nat | i < n} (lcd: !lcd_t, str: string (n), pos: size_t (i)): void = { val () = loop (lcd, str, pos) val () = forever (lcd, str, pos) } val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7) val () = forever (lcd, g_str_message, i2sz 0) val () = lcd_close lcd } fun forever {n:int}{i:nat | i < n} (lcd: !lcd_t, str: string (n), pos: size_t (i)): void = { val () = loop (lcd, str, pos) val () = forever (lcd, str, pos) } val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7) val () = forever (lcd, g_str_message, i2sz 0) val () = lcd_close lcd }
  • 25. Binary size efficiencyBinary size efficiencyBinary size efficiencyBinary size efficiencyBinary size efficiency For examples on "Getting Started with Arduino", ATS has good binary size efficiency as well as C. For examples on "Getting Started with Arduino", ATS has good binary size efficiency as well as C. For examples on "Getting Started with Arduino", ATS has good binary size efficiency as well as C. For examples on "Getting Started with Arduino", ATS has good binary size efficiency as well as C. For examples on "Getting Started with Arduino", ATS has good binary size efficiency as well as C.
  • 26. ConclusionConclusionConclusionConclusionConclusion ☆ Can we directly use functional style programming on embedded system? ☆ Can we directly use functional style programming on embedded system? ☆ Can we directly use functional style programming on embedded system? ☆ Can we directly use functional style programming on embedded system? ☆ Can we directly use functional style programming on embedded system? ☆ ⇒ Yes, with ATS language.☆ ⇒ Yes, with ATS language.☆ ⇒ Yes, with ATS language.☆ ⇒ Yes, with ATS language.☆ ⇒ Yes, with ATS language. ☆ Can we make more safety than C language on embedded system? ☆ Can we make more safety than C language on embedded system? ☆ Can we make more safety than C language on embedded system? ☆ Can we make more safety than C language on embedded system? ☆ Can we make more safety than C language on embedded system? ☆ ⇒ Yes, with ATS language.☆ ⇒ Yes, with ATS language.☆ ⇒ Yes, with ATS language.☆ ⇒ Yes, with ATS language.☆ ⇒ Yes, with ATS language. https://github.com/fpiot/arduino-atshttps://github.com/fpiot/arduino-atshttps://github.com/fpiot/arduino-atshttps://github.com/fpiot/arduino-atshttps://github.com/fpiot/arduino-ats
  • 27. License of photos #1License of photos #1License of photos #1License of photos #1License of photos #1 * Minecraft toys | Flickr - Photo Sharing! https://www.flickr.com/photos/sergesegal/15976451410/ Copyright: 2015 Sergey Galyonkin / License: CC BY-SA 2.0 * Arduino Uno | Flickr - Photo Sharing! https://www.flickr.com/photos/snootlab/6052455554/ Copyright: Snootlab / License: CC BY 2.0 * Thank You Dennis Ritchie | Flickr - Photo Sharing! https://www.flickr.com/photos/vincentpants/6239875256/ Copyright: Vincent van Haaff / License: CC BY-SA 2.0 * Climbing Journal Mount Rinjani package | Flickr - Photo Sharing! https://www.flickr.com/photos/trekkingrinjani/4930552641/ Copyright: Trekking Rinjani / License: CC BY 2.0 * Recycling Grunge Sign | Flickr - Photo Sharing! https://www.flickr.com/photos/80497449@N04/8677649972/ Copyright: Nicolas Raymond / License: CC BY 2.0 * IMG_4097 | Flickr - Photo Sharing! https://www.flickr.com/photos/matthewpiatt/1562708158/ Copyright: Matthew Piatt / License: CC BY-SA 2.0 * Seagulls in Flight | Flickr - Photo Sharing! https://www.flickr.com/photos/87007001@N04/13513835453/ Copyright: Shaun Fisher / License: CC BY 2.0 * Minecraft toys | Flickr - Photo Sharing! https://www.flickr.com/photos/sergesegal/15976451410/ Copyright: 2015 Sergey Galyonkin / License: CC BY-SA 2.0 * Arduino Uno | Flickr - Photo Sharing! https://www.flickr.com/photos/snootlab/6052455554/ Copyright: Snootlab / License: CC BY 2.0 * Thank You Dennis Ritchie | Flickr - Photo Sharing! https://www.flickr.com/photos/vincentpants/6239875256/ Copyright: Vincent van Haaff / License: CC BY-SA 2.0 * Climbing Journal Mount Rinjani package | Flickr - Photo Sharing! https://www.flickr.com/photos/trekkingrinjani/4930552641/ Copyright: Trekking Rinjani / License: CC BY 2.0 * Recycling Grunge Sign | Flickr - Photo Sharing! https://www.flickr.com/photos/80497449@N04/8677649972/ Copyright: Nicolas Raymond / License: CC BY 2.0 * IMG_4097 | Flickr - Photo Sharing! https://www.flickr.com/photos/matthewpiatt/1562708158/ Copyright: Matthew Piatt / License: CC BY-SA 2.0 * Seagulls in Flight | Flickr - Photo Sharing! https://www.flickr.com/photos/87007001@N04/13513835453/ Copyright: Shaun Fisher / License: CC BY 2.0 * Minecraft toys | Flickr - Photo Sharing! https://www.flickr.com/photos/sergesegal/15976451410/ Copyright: 2015 Sergey Galyonkin / License: CC BY-SA 2.0 * Arduino Uno | Flickr - Photo Sharing! https://www.flickr.com/photos/snootlab/6052455554/ Copyright: Snootlab / License: CC BY 2.0 * Thank You Dennis Ritchie | Flickr - Photo Sharing! https://www.flickr.com/photos/vincentpants/6239875256/ Copyright: Vincent van Haaff / License: CC BY-SA 2.0 * Climbing Journal Mount Rinjani package | Flickr - Photo Sharing! https://www.flickr.com/photos/trekkingrinjani/4930552641/ Copyright: Trekking Rinjani / License: CC BY 2.0 * Recycling Grunge Sign | Flickr - Photo Sharing! https://www.flickr.com/photos/80497449@N04/8677649972/ Copyright: Nicolas Raymond / License: CC BY 2.0 * IMG_4097 | Flickr - Photo Sharing! https://www.flickr.com/photos/matthewpiatt/1562708158/ Copyright: Matthew Piatt / License: CC BY-SA 2.0 * Seagulls in Flight | Flickr - Photo Sharing! https://www.flickr.com/photos/87007001@N04/13513835453/ Copyright: Shaun Fisher / License: CC BY 2.0 * Minecraft toys | Flickr - Photo Sharing! https://www.flickr.com/photos/sergesegal/15976451410/ Copyright: 2015 Sergey Galyonkin / License: CC BY-SA 2.0 * Arduino Uno | Flickr - Photo Sharing! https://www.flickr.com/photos/snootlab/6052455554/ Copyright: Snootlab / License: CC BY 2.0 * Thank You Dennis Ritchie | Flickr - Photo Sharing! https://www.flickr.com/photos/vincentpants/6239875256/ Copyright: Vincent van Haaff / License: CC BY-SA 2.0 * Climbing Journal Mount Rinjani package | Flickr - Photo Sharing! https://www.flickr.com/photos/trekkingrinjani/4930552641/ Copyright: Trekking Rinjani / License: CC BY 2.0 * Recycling Grunge Sign | Flickr - Photo Sharing! https://www.flickr.com/photos/80497449@N04/8677649972/ Copyright: Nicolas Raymond / License: CC BY 2.0 * IMG_4097 | Flickr - Photo Sharing! https://www.flickr.com/photos/matthewpiatt/1562708158/ Copyright: Matthew Piatt / License: CC BY-SA 2.0 * Seagulls in Flight | Flickr - Photo Sharing! https://www.flickr.com/photos/87007001@N04/13513835453/ Copyright: Shaun Fisher / License: CC BY 2.0 * Minecraft toys | Flickr - Photo Sharing! https://www.flickr.com/photos/sergesegal/15976451410/ Copyright: 2015 Sergey Galyonkin / License: CC BY-SA 2.0 * Arduino Uno | Flickr - Photo Sharing! https://www.flickr.com/photos/snootlab/6052455554/ Copyright: Snootlab / License: CC BY 2.0 * Thank You Dennis Ritchie | Flickr - Photo Sharing! https://www.flickr.com/photos/vincentpants/6239875256/ Copyright: Vincent van Haaff / License: CC BY-SA 2.0 * Climbing Journal Mount Rinjani package | Flickr - Photo Sharing! https://www.flickr.com/photos/trekkingrinjani/4930552641/ Copyright: Trekking Rinjani / License: CC BY 2.0 * Recycling Grunge Sign | Flickr - Photo Sharing! https://www.flickr.com/photos/80497449@N04/8677649972/ Copyright: Nicolas Raymond / License: CC BY 2.0 * IMG_4097 | Flickr - Photo Sharing! https://www.flickr.com/photos/matthewpiatt/1562708158/ Copyright: Matthew Piatt / License: CC BY-SA 2.0 * Seagulls in Flight | Flickr - Photo Sharing! https://www.flickr.com/photos/87007001@N04/13513835453/ Copyright: Shaun Fisher / License: CC BY 2.0
  • 28. License of photos #2License of photos #2License of photos #2License of photos #2License of photos #2 * Arduino Uno unboxing | Flickr - Photo Sharing! https://www.flickr.com/photos/mightyohm/5052594028/ Copyright: Jeff Keyzer / License: CC BY-SA 2.0 * Creative Commons BBB | Flickr - Photo Sharing! https://www.flickr.com/photos/steren/2732488224/ Copyright: Steren Giannini / License: CC BY 2.0 * LED | Flickr - Photo Sharing! https://www.flickr.com/photos/nao904/6084536885/ Copyright: Nao. Fujita / License: CC BY 2.0 * Pagoda's curly steps | Flickr - Photo Sharing! https://www.flickr.com/photos/kewl/6834141860/ Copyright: Tristan Schmurr / License: CC BY 2.0 * Arduino Uno unboxing | Flickr - Photo Sharing! https://www.flickr.com/photos/mightyohm/5052594028/ Copyright: Jeff Keyzer / License: CC BY-SA 2.0 * Creative Commons BBB | Flickr - Photo Sharing! https://www.flickr.com/photos/steren/2732488224/ Copyright: Steren Giannini / License: CC BY 2.0 * LED | Flickr - Photo Sharing! https://www.flickr.com/photos/nao904/6084536885/ Copyright: Nao. Fujita / License: CC BY 2.0 * Pagoda's curly steps | Flickr - Photo Sharing! https://www.flickr.com/photos/kewl/6834141860/ Copyright: Tristan Schmurr / License: CC BY 2.0 * Arduino Uno unboxing | Flickr - Photo Sharing! https://www.flickr.com/photos/mightyohm/5052594028/ Copyright: Jeff Keyzer / License: CC BY-SA 2.0 * Creative Commons BBB | Flickr - Photo Sharing! https://www.flickr.com/photos/steren/2732488224/ Copyright: Steren Giannini / License: CC BY 2.0 * LED | Flickr - Photo Sharing! https://www.flickr.com/photos/nao904/6084536885/ Copyright: Nao. Fujita / License: CC BY 2.0 * Pagoda's curly steps | Flickr - Photo Sharing! https://www.flickr.com/photos/kewl/6834141860/ Copyright: Tristan Schmurr / License: CC BY 2.0 * Arduino Uno unboxing | Flickr - Photo Sharing! https://www.flickr.com/photos/mightyohm/5052594028/ Copyright: Jeff Keyzer / License: CC BY-SA 2.0 * Creative Commons BBB | Flickr - Photo Sharing! https://www.flickr.com/photos/steren/2732488224/ Copyright: Steren Giannini / License: CC BY 2.0 * LED | Flickr - Photo Sharing! https://www.flickr.com/photos/nao904/6084536885/ Copyright: Nao. Fujita / License: CC BY 2.0 * Pagoda's curly steps | Flickr - Photo Sharing! https://www.flickr.com/photos/kewl/6834141860/ Copyright: Tristan Schmurr / License: CC BY 2.0 * Arduino Uno unboxing | Flickr - Photo Sharing! https://www.flickr.com/photos/mightyohm/5052594028/ Copyright: Jeff Keyzer / License: CC BY-SA 2.0 * Creative Commons BBB | Flickr - Photo Sharing! https://www.flickr.com/photos/steren/2732488224/ Copyright: Steren Giannini / License: CC BY 2.0 * LED | Flickr - Photo Sharing! https://www.flickr.com/photos/nao904/6084536885/ Copyright: Nao. Fujita / License: CC BY 2.0 * Pagoda's curly steps | Flickr - Photo Sharing! https://www.flickr.com/photos/kewl/6834141860/ Copyright: Tristan Schmurr / License: CC BY 2.0