Static typing and proof in ATS
language
Static typing and proof in ATS
language
Static typing and proof in ATS
language
Static typing and proof in ATS
language
Static typing and proof in ATS
language
Kiwamu OkabeKiwamu OkabeKiwamu OkabeKiwamu OkabeKiwamu Okabe
Let's make Rock-paper-scissors libraryLet's make Rock-paper-scissors libraryLet's make Rock-paper-scissors libraryLet's make Rock-paper-scissors libraryLet's make Rock-paper-scissors library
☆ �じゃんけん� in Japanese.☆ �じゃんけん� in Japanese.☆ �じゃんけん� in Japanese.☆ �じゃんけん� in Japanese.☆ �じゃんけん� in Japanese.
R-P-S in C language #1R-P-S in C language #1R-P-S in C language #1R-P-S in C language #1R-P-S in C language #1
#include�<stdio.h>
#include�<stdlib.h>
typedef�enum�{
R_RPS_T�=�0,�/*�Rock�*/
P_RPS_T,�����/*�Paper�*/
S_RPS_T������/*�Scissors�*/
}�rps_t;
void�print_rps(rps_t�x)�{
switch�(x)�{
case�R_RPS_T:
printf("Rock");�break;
case�P_RPS_T:
printf("Paper");�break;
case�S_RPS_T:
printf("Scissors");�break;
}
}
#include�<stdio.h>
#include�<stdlib.h>
typedef�enum�{
R_RPS_T�=�0,�/*�Rock�*/
P_RPS_T,�����/*�Paper�*/
S_RPS_T������/*�Scissors�*/
}�rps_t;
void�print_rps(rps_t�x)�{
switch�(x)�{
case�R_RPS_T:
printf("Rock");�break;
case�P_RPS_T:
printf("Paper");�break;
case�S_RPS_T:
printf("Scissors");�break;
}
}
#include�<stdio.h>
#include�<stdlib.h>
typedef�enum�{
R_RPS_T�=�0,�/*�Rock�*/
P_RPS_T,�����/*�Paper�*/
S_RPS_T������/*�Scissors�*/
}�rps_t;
void�print_rps(rps_t�x)�{
switch�(x)�{
case�R_RPS_T:
printf("Rock");�break;
case�P_RPS_T:
printf("Paper");�break;
case�S_RPS_T:
printf("Scissors");�break;
}
}
#include�<stdio.h>
#include�<stdlib.h>
typedef�enum�{
R_RPS_T�=�0,�/*�Rock�*/
P_RPS_T,�����/*�Paper�*/
S_RPS_T������/*�Scissors�*/
}�rps_t;
void�print_rps(rps_t�x)�{
switch�(x)�{
case�R_RPS_T:
printf("Rock");�break;
case�P_RPS_T:
printf("Paper");�break;
case�S_RPS_T:
printf("Scissors");�break;
}
}
#include�<stdio.h>
#include�<stdlib.h>
typedef enum�{
R_RPS_T�=�0,�/*�Rock�*/
P_RPS_T,�����/*�Paper�*/
S_RPS_T������/*�Scissors�*/
}�rps_t;
void�print_rps(rps_t�x)�{
switch�(x)�{
case�R_RPS_T:
printf("Rock");�break;
case�P_RPS_T:
printf("Paper");�break;
case�S_RPS_T:
printf("Scissors");�break;
}
}
R-P-S in C language #2R-P-S in C language #2R-P-S in C language #2R-P-S in C language #2R-P-S in C language #2
int�main()�{
rps_t�paper_d�=�P_RPS_T;
rps_t�win_d�=�rps_win_d�(paper_d);
print_rps(win_d);�printf("�win�");�print_rps(paper_d);�printf(".n");
/*�=>�Scissors�win�Paper.�*/
rps_t�even_d�=�rps_even_d(win_d,�paper_d);
print_rps(even_d);�printf("�is�even�between�");�print_rps(win_d);
printf("�and�");�print_rps(paper_d);�printf(".n");
/*�=>�Rock�is�even�between�Scissors�and�Paper.�*/
}
int�main()�{
rps_t�paper_d�=�P_RPS_T;
rps_t�win_d�=�rps_win_d�(paper_d);
print_rps(win_d);�printf("�win�");�print_rps(paper_d);�printf(".n");
/*�=>�Scissors�win�Paper.�*/
rps_t�even_d�=�rps_even_d(win_d,�paper_d);
print_rps(even_d);�printf("�is�even�between�");�print_rps(win_d);
printf("�and�");�print_rps(paper_d);�printf(".n");
/*�=>�Rock�is�even�between�Scissors�and�Paper.�*/
}
int�main()�{
rps_t�paper_d�=�P_RPS_T;
rps_t�win_d�=�rps_win_d�(paper_d);
print_rps(win_d);�printf("�win�");�print_rps(paper_d);�printf(".n");
/*�=>�Scissors�win�Paper.�*/
rps_t�even_d�=�rps_even_d(win_d,�paper_d);
print_rps(even_d);�printf("�is�even�between�");�print_rps(win_d);
printf("�and�");�print_rps(paper_d);�printf(".n");
/*�=>�Rock�is�even�between�Scissors�and�Paper.�*/
}
int�main()�{
rps_t�paper_d�=�P_RPS_T;
rps_t�win_d�=�rps_win_d�(paper_d);
print_rps(win_d);�printf("�win�");�print_rps(paper_d);�printf(".n");
/*�=>�Scissors�win�Paper.�*/
rps_t�even_d�=�rps_even_d(win_d,�paper_d);
print_rps(even_d);�printf("�is�even�between�");�print_rps(win_d);
printf("�and�");�print_rps(paper_d);�printf(".n");
/*�=>�Rock�is�even�between�Scissors�and�Paper.�*/
}
int�main()�{
rps_t�paper_d�=�P_RPS_T;
rps_t�win_d�=�rps_win_d�(paper_d);
print_rps(win_d);�printf("�win�");�print_rps(paper_d);�printf(".n");
/*�=>�Scissors�win�Paper.�*/
rps_t�even_d�=�rps_even_d(win_d,�paper_d);
print_rps(even_d);�printf("�is�even�between�");�print_rps(win_d);
printf("�and�");�print_rps(paper_d);�printf(".n");
/*�=>�Rock�is�even�between�Scissors�and�Paper.�*/
}
R-P-S in C language #3R-P-S in C language #3R-P-S in C language #3R-P-S in C language #3R-P-S in C language #3
rps_t�rps_win_d(rps_t�x)�{
switch�(x)�{
case�R_RPS_T:
return�P_RPS_T;
case�P_RPS_T:
return�S_RPS_T;
case�S_RPS_T:
return�R_RPS_T;
default:
abort();
}
}
#define�PACK(X,Y)�((X)<<4�│�(Y))
rps_t�rps_even_d(rps_t�x,�rps_t�y)�{
switch�(PACK(x,�y))�{
case�PACK(P_RPS_T,�R_RPS_T):
case�PACK(S_RPS_T,�P_RPS_T):
case�PACK(R_RPS_T,�S_RPS_T):
return�rps_win_d(x);
default:
abort();
}
}
rps_t�rps_win_d(rps_t�x)�{
switch�(x)�{
case�R_RPS_T:
return�P_RPS_T;
case�P_RPS_T:
return�S_RPS_T;
case�S_RPS_T:
return�R_RPS_T;
default:
abort();
}
}
#define�PACK(X,Y)�((X)<<4�│�(Y))
rps_t�rps_even_d(rps_t�x,�rps_t�y)�{
switch�(PACK(x,�y))�{
case�PACK(P_RPS_T,�R_RPS_T):
case�PACK(S_RPS_T,�P_RPS_T):
case�PACK(R_RPS_T,�S_RPS_T):
return�rps_win_d(x);
default:
abort();
}
}
rps_t�rps_win_d(rps_t�x)�{
switch�(x)�{
case�R_RPS_T:
return�P_RPS_T;
case�P_RPS_T:
return�S_RPS_T;
case�S_RPS_T:
return�R_RPS_T;
default:
abort();
}
}
#define�PACK(X,Y)�((X)<<4�│�(Y))
rps_t�rps_even_d(rps_t�x,�rps_t�y)�{
switch�(PACK(x,�y))�{
case�PACK(P_RPS_T,�R_RPS_T):
case�PACK(S_RPS_T,�P_RPS_T):
case�PACK(R_RPS_T,�S_RPS_T):
return�rps_win_d(x);
default:
abort();
}
}
rps_t�rps_win_d(rps_t�x)�{
switch�(x)�{
case�R_RPS_T:
return�P_RPS_T;
case�P_RPS_T:
return�S_RPS_T;
case�S_RPS_T:
return�R_RPS_T;
default:
abort();
}
}
#define�PACK(X,Y)�((X)<<4�│�(Y))
rps_t�rps_even_d(rps_t�x,�rps_t�y)�{
switch�(PACK(x,�y))�{
case�PACK(P_RPS_T,�R_RPS_T):
case�PACK(S_RPS_T,�P_RPS_T):
case�PACK(R_RPS_T,�S_RPS_T):
return�rps_win_d(x);
default:
abort();
}
}
rps_t�rps_win_d(rps_t�x)�{
switch�(x)�{
case�R_RPS_T:
return�P_RPS_T;
case�P_RPS_T:
return�S_RPS_T;
case�S_RPS_T:
return�R_RPS_T;
default:
abort();
}
}
#define�PACK(X,Y)�((X)<<4�│�(Y))
rps_t�rps_even_d(rps_t�x,�rps_t�y)�{
switch�(PACK(x,�y))�{
case�PACK(P_RPS_T,�R_RPS_T):
case�PACK(S_RPS_T,�P_RPS_T):
case�PACK(R_RPS_T,�S_RPS_T):
return�rps_win_d(x);
default:
abort();
}
}
However you can make run-time errorHowever you can make run-time errorHowever you can make run-time errorHowever you can make run-time errorHowever you can make run-time error
rps_t�rps_win_d(rps_t�x)�{
switch�(x)�{
case�R_RPS_T:
return�R_RPS_T;�/*�Run-time�error!�*/
case�P_RPS_T:
return�S_RPS_T;
/* case�S_RPS_T:
return�R_RPS_T;�*/�/*�Not�exhaustive!�*/
default:
abort();�/*�Abort�occurs!�*/
}
}
#define�PACK(X,Y)�((X)<<4�│�(Y))
rps_t�rps_even_d(rps_t�x,�rps_t�y)�{
switch�(PACK(x,�y))�{
case�PACK(P_RPS_T,�R_RPS_T):
case�PACK(S_RPS_T,�P_RPS_T):
case�PACK(R_RPS_T,�S_RPS_T):
return�rps_win_d(y);�/*�Run-time�error!�*/
default:
abort();�/*�Abort�occurs!�*/
}
}
rps_t�rps_win_d(rps_t�x)�{
switch�(x)�{
case�R_RPS_T:
return�R_RPS_T;�/*�Run-time�error!�*/
case�P_RPS_T:
return�S_RPS_T;
/* case�S_RPS_T:
return�R_RPS_T;�*/�/*�Not�exhaustive!�*/
default:
abort();�/*�Abort�occurs!�*/
}
}
#define�PACK(X,Y)�((X)<<4�│�(Y))
rps_t�rps_even_d(rps_t�x,�rps_t�y)�{
switch�(PACK(x,�y))�{
case�PACK(P_RPS_T,�R_RPS_T):
case�PACK(S_RPS_T,�P_RPS_T):
case�PACK(R_RPS_T,�S_RPS_T):
return�rps_win_d(y);�/*�Run-time�error!�*/
default:
abort();�/*�Abort�occurs!�*/
}
}
rps_t�rps_win_d(rps_t�x)�{
switch�(x)�{
case�R_RPS_T:
return�R_RPS_T;�/*�Run-time�error!�*/
case�P_RPS_T:
return�S_RPS_T;
/* case�S_RPS_T:
return�R_RPS_T;�*/�/*�Not�exhaustive!�*/
default:
abort();�/*�Abort�occurs!�*/
}
}
#define�PACK(X,Y)�((X)<<4�│�(Y))
rps_t�rps_even_d(rps_t�x,�rps_t�y)�{
switch�(PACK(x,�y))�{
case�PACK(P_RPS_T,�R_RPS_T):
case�PACK(S_RPS_T,�P_RPS_T):
case�PACK(R_RPS_T,�S_RPS_T):
return�rps_win_d(y);�/*�Run-time�error!�*/
default:
abort();�/*�Abort�occurs!�*/
}
}
rps_t�rps_win_d(rps_t�x)�{
switch�(x)�{
case�R_RPS_T:
return�R_RPS_T;�/*�Run-time�error!�*/
case�P_RPS_T:
return�S_RPS_T;
/* case�S_RPS_T:
return�R_RPS_T;�*/�/*�Not�exhaustive!�*/
default:
abort();�/*�Abort�occurs!�*/
}
}
#define�PACK(X,Y)�((X)<<4�│�(Y))
rps_t�rps_even_d(rps_t�x,�rps_t�y)�{
switch�(PACK(x,�y))�{
case�PACK(P_RPS_T,�R_RPS_T):
case�PACK(S_RPS_T,�P_RPS_T):
case�PACK(R_RPS_T,�S_RPS_T):
return�rps_win_d(y);�/*�Run-time�error!�*/
default:
abort();�/*�Abort�occurs!�*/
}
}
rps_t�rps_win_d(rps_t�x)�{
switch�(x)�{
case�R_RPS_T:
return�R_RPS_T;�/*�Run-time�error!�*/
case�P_RPS_T:
return�S_RPS_T;
/* case�S_RPS_T:
return�R_RPS_T;�*/ /*�Not�exhaustive!�*/
default:
abort();�/*�Abort�occurs!�*/
}
}
#define�PACK(X,Y)�((X)<<4�│�(Y))
rps_t�rps_even_d(rps_t�x,�rps_t�y)�{
switch�(PACK(x,�y))�{
case�PACK(P_RPS_T,�R_RPS_T):
case�PACK(S_RPS_T,�P_RPS_T):
case�PACK(R_RPS_T,�S_RPS_T):
return�rps_win_d(y);�/*�Run-time�error!�*/
default:
abort();�/*�Abort�occurs!�*/
}
}
Please imagine specification on codePlease imagine specification on codePlease imagine specification on codePlease imagine specification on codePlease imagine specification on code
☆ Introduce specification using static typing.☆ Introduce specification using static typing.☆ Introduce specification using static typing.☆ Introduce specification using static typing.☆ Introduce specification using static typing.
☆ You will get more compile-time errors.☆ You will get more compile-time errors.☆ You will get more compile-time errors.☆ You will get more compile-time errors.☆ You will get more compile-time errors.
☆ You will get less run-time errors.☆ You will get less run-time errors.☆ You will get less run-time errors.☆ You will get less run-time errors.☆ You will get less run-time errors.
☆ You can do that in ATS language.☆ You can do that in ATS language.☆ You can do that in ATS language.☆ You can do that in ATS language.☆ You can do that in ATS language.
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
More strong type can be used on the ATS.More strong type can be used on the ATS.More strong type can be used on the ATS.More strong type can be used on the ATS.More strong type can be used on the ATS.
DML-style dependent types in ATSDML-style dependent types in ATSDML-style dependent types in ATSDML-style dependent types in ATSDML-style dependent types in ATS
Type of R-P-S in ATSType of R-P-S in ATSType of R-P-S in ATSType of R-P-S in ATSType of R-P-S in ATS
datasort�rps_s�=
��│�r_rps_s�(*�Rock�*)
��│�p_rps_s�(*�Paper�*)
��│�s_rps_s�(*�Scissors�*)
datatype�rps_t�(rps_s)�=
��│�r_rps_t�(r_rps_s)�(*�Rock�*)
��│�p_rps_t�(p_rps_s)�(*�Paper�*)
��│�s_rps_t�(s_rps_s)�(*�Scissors�*)
typedef�rps_t_any�=�[x:rps_s]�rps_t�(x)
datasort�rps_s�=
��│�r_rps_s�(*�Rock�*)
��│�p_rps_s�(*�Paper�*)
��│�s_rps_s�(*�Scissors�*)
datatype�rps_t�(rps_s)�=
��│�r_rps_t�(r_rps_s)�(*�Rock�*)
��│�p_rps_t�(p_rps_s)�(*�Paper�*)
��│�s_rps_t�(s_rps_s)�(*�Scissors�*)
typedef�rps_t_any�=�[x:rps_s]�rps_t�(x)
datasort�rps_s�=
��│�r_rps_s�(*�Rock�*)
��│�p_rps_s�(*�Paper�*)
��│�s_rps_s�(*�Scissors�*)
datatype�rps_t�(rps_s)�=
��│�r_rps_t�(r_rps_s)�(*�Rock�*)
��│�p_rps_t�(p_rps_s)�(*�Paper�*)
��│�s_rps_t�(s_rps_s)�(*�Scissors�*)
typedef�rps_t_any�=�[x:rps_s]�rps_t�(x)
datasort�rps_s�=
��│�r_rps_s�(*�Rock�*)
��│�p_rps_s�(*�Paper�*)
��│�s_rps_s�(*�Scissors�*)
datatype�rps_t�(rps_s)�=
��│�r_rps_t�(r_rps_s)�(*�Rock�*)
��│�p_rps_t�(p_rps_s)�(*�Paper�*)
��│�s_rps_t�(s_rps_s)�(*�Scissors�*)
typedef�rps_t_any�=�[x:rps_s]�rps_t�(x)
datasort�rps_s�=
��│�r_rps_s�(*�Rock�*)
��│�p_rps_s�(*�Paper�*)
��│�s_rps_s�(*�Scissors�*)
datatype�rps_t�(rps_s)�=
��│�r_rps_t�(r_rps_s)�(*�Rock�*)
��│�p_rps_t�(p_rps_s)�(*�Paper�*)
��│�s_rps_t�(s_rps_s)�(*�Scissors�*)
typedef�rps_t_any�=�[x:rps_s]�rps_t�(x)
Only use Dynamics of ATSOnly use Dynamics of ATSOnly use Dynamics of ATSOnly use Dynamics of ATSOnly use Dynamics of ATS
fun{}�rps_win_d�(x:�rps_t_any):�rps_t_any
fun{}�rps_even_d�(x:�rps_t_any,�y:�rps_t_any):�rps_t_any�(*�The�x�should�win�
the�y.�*)
implement{}�rps_win_d�(x)�=
��case+�x�of
��│�r_rps_t()�=>�p_rps_t()
��│�p_rps_t()�=>�s_rps_t()
��│�s_rps_t()�=>�r_rps_t()
implement{}�rps_even_d�(x,�y)�=
��case+�(x,�y)�of
��│�(p_rps_t(),�r_rps_t())�=>�rps_win_d�(x)
��│�(s_rps_t(),�p_rps_t())�=>�rps_win_d�(x)
��│�(r_rps_t(),�s_rps_t())�=>�rps_win_d�(x)
��│�(_,�_)�=>�$raise�GenerallyExn("The�x�should�win�the�y.")
fun{}�rps_win_d�(x:�rps_t_any):�rps_t_any
fun{}�rps_even_d�(x:�rps_t_any,�y:�rps_t_any):�rps_t_any�(*�The�x�should�win�
the�y.�*)
implement{}�rps_win_d�(x)�=
��case+�x�of
��│�r_rps_t()�=>�p_rps_t()
��│�p_rps_t()�=>�s_rps_t()
��│�s_rps_t()�=>�r_rps_t()
implement{}�rps_even_d�(x,�y)�=
��case+�(x,�y)�of
��│�(p_rps_t(),�r_rps_t())�=>�rps_win_d�(x)
��│�(s_rps_t(),�p_rps_t())�=>�rps_win_d�(x)
��│�(r_rps_t(),�s_rps_t())�=>�rps_win_d�(x)
��│�(_,�_)�=>�$raise�GenerallyExn("The�x�should�win�the�y.")
fun{}�rps_win_d�(x:�rps_t_any):�rps_t_any
fun{}�rps_even_d�(x:�rps_t_any,�y:�rps_t_any):�rps_t_any�(*�The�x�should�win�
the�y.�*)
implement{}�rps_win_d�(x)�=
��case+�x�of
��│�r_rps_t()�=>�p_rps_t()
��│�p_rps_t()�=>�s_rps_t()
��│�s_rps_t()�=>�r_rps_t()
implement{}�rps_even_d�(x,�y)�=
��case+�(x,�y)�of
��│�(p_rps_t(),�r_rps_t())�=>�rps_win_d�(x)
��│�(s_rps_t(),�p_rps_t())�=>�rps_win_d�(x)
��│�(r_rps_t(),�s_rps_t())�=>�rps_win_d�(x)
��│�(_,�_)�=>�$raise�GenerallyExn("The�x�should�win�the�y.")
fun{}�rps_win_d�(x:�rps_t_any):�rps_t_any
fun{}�rps_even_d�(x:�rps_t_any,�y:�rps_t_any):�rps_t_any�(*�The�x�should�win�
the�y.�*)
implement{}�rps_win_d�(x)�=
��case+�x�of
��│�r_rps_t()�=>�p_rps_t()
��│�p_rps_t()�=>�s_rps_t()
��│�s_rps_t()�=>�r_rps_t()
implement{}�rps_even_d�(x,�y)�=
��case+�(x,�y)�of
��│�(p_rps_t(),�r_rps_t())�=>�rps_win_d�(x)
��│�(s_rps_t(),�p_rps_t())�=>�rps_win_d�(x)
��│�(r_rps_t(),�s_rps_t())�=>�rps_win_d�(x)
��│�(_,�_)�=>�$raise�GenerallyExn("The�x�should�win�the�y.")
fun{}�rps_win_d�(x:�rps_t_any):�rps_t_any
fun{}�rps_even_d�(x:�rps_t_any,�y:�rps_t_any):�rps_t_any�(*�The�x�should�win�
the�y.�*)
implement{}�rps_win_d�(x)�=
��case+�x�of
��│�r_rps_t()�=>�p_rps_t()
��│�p_rps_t()�=>�s_rps_t()
��│�s_rps_t()�=>�r_rps_t()
implement{}�rps_even_d�(x,�y)�=
��case+�(x,�y)�of
��│�(p_rps_t(),�r_rps_t())�=>�rps_win_d�(x)
��│�(s_rps_t(),�p_rps_t())�=>�rps_win_d�(x)
��│�(r_rps_t(),�s_rps_t())�=>�rps_win_d�(x)
��│�(_,�_)�=>�$raise�GenerallyExn("The�x�should�win�the�y.")
Also you can make run-time errorAlso you can make run-time errorAlso you can make run-time errorAlso you can make run-time errorAlso you can make run-time error
implement{}�rps_win_d�(x)�=
��case+�x�of
��│�r_rps_t()�=>�r_rps_t()�(*�Run-time�error!�*)
��│�p_rps_t()�=>�s_rps_t()
(*│�s_rps_t()�=>�r_rps_t()�*)�(*�Compile-time�error!�*)
implement{}�rps_even_d�(x,�y)�=
��case+�(x,�y)�of
��│�(p_rps_t(),�r_rps_t())�=>�rps_win_d�(x)
��│�(s_rps_t(),�p_rps_t())�=>�rps_win_d�(y)�(*�Run-time�error!�*)
��│�(r_rps_t(),�s_rps_t())�=>�rps_win_d�(x)
��│�(_,�_)�=>�$raise�GenerallyExn("The�x�should�win�the�y.")�(*�Exception�
occurs!�*)
implement{}�rps_win_d�(x)�=
��case+�x�of
��│�r_rps_t()�=>�r_rps_t()�(*�Run-time�error!�*)
��│�p_rps_t()�=>�s_rps_t()
(*│�s_rps_t()�=>�r_rps_t()�*)�(*�Compile-time�error!�*)
implement{}�rps_even_d�(x,�y)�=
��case+�(x,�y)�of
��│�(p_rps_t(),�r_rps_t())�=>�rps_win_d�(x)
��│�(s_rps_t(),�p_rps_t())�=>�rps_win_d�(y)�(*�Run-time�error!�*)
��│�(r_rps_t(),�s_rps_t())�=>�rps_win_d�(x)
��│�(_,�_)�=>�$raise�GenerallyExn("The�x�should�win�the�y.")�(*�Exception�
occurs!�*)
implement{}�rps_win_d�(x)�=
��case+�x�of
��│�r_rps_t()�=>�r_rps_t()�(*�Run-time�error!�*)
��│�p_rps_t()�=>�s_rps_t()
(*│�s_rps_t()�=>�r_rps_t()�*)�(*�Compile-time�error!�*)
implement{}�rps_even_d�(x,�y)�=
��case+�(x,�y)�of
��│�(p_rps_t(),�r_rps_t())�=>�rps_win_d�(x)
��│�(s_rps_t(),�p_rps_t())�=>�rps_win_d�(y)�(*�Run-time�error!�*)
��│�(r_rps_t(),�s_rps_t())�=>�rps_win_d�(x)
��│�(_,�_)�=>�$raise�GenerallyExn("The�x�should�win�the�y.")�(*�Exception�
occurs!�*)
implement{}�rps_win_d�(x)�=
��case+�x�of
��│�r_rps_t()�=>�r_rps_t()�(*�Run-time�error!�*)
��│�p_rps_t()�=>�s_rps_t()
(*│�s_rps_t()�=>�r_rps_t()�*)�(*�Compile-time�error!�*)
implement{}�rps_even_d�(x,�y)�=
��case+�(x,�y)�of
��│�(p_rps_t(),�r_rps_t())�=>�rps_win_d�(x)
��│�(s_rps_t(),�p_rps_t())�=>�rps_win_d�(y)�(*�Run-time�error!�*)
��│�(r_rps_t(),�s_rps_t())�=>�rps_win_d�(x)
��│�(_,�_)�=>�$raise�GenerallyExn("The�x�should�win�the�y.")�(*�Exception�
occurs!�*)
implement{}�rps_win_d�(x)�=
��case+�x�of
��│�r_rps_t()�=>�r_rps_t()�(*�Run-time�error!�*)
��│�p_rps_t()�=>�s_rps_t()
(*│�s_rps_t()�=>�r_rps_t()�*) (*�Compile-time�error!�*)
implement{}�rps_even_d�(x,�y)�=
��case+�(x,�y)�of
��│�(p_rps_t(),�r_rps_t())�=>�rps_win_d�(x)
��│�(s_rps_t(),�p_rps_t())�=>�rps_win_d�(y)�(*�Run-time�error!�*)
��│�(r_rps_t(),�s_rps_t())�=>�rps_win_d�(x)
��│�(_,�_)�=>�$raise�GenerallyExn("The�x�should�win�the�y.")�(*�Exception�
occurs!�*)
It's caused by having no specification in the
implementation. ATS language can have
specification as Statics or Proofs.
It's caused by having no specification in the
implementation. ATS language can have
specification as Statics or Proofs.
It's caused by having no specification in the
implementation. ATS language can have
specification as Statics or Proofs.
It's caused by having no specification in the
implementation. ATS language can have
specification as Statics or Proofs.
It's caused by having no specification in the
implementation. ATS language can have
specification as Statics or Proofs.
Specification using Statics of ATSSpecification using Statics of ATSSpecification using Statics of ATSSpecification using Statics of ATSSpecification using Statics of ATS
stacst�rps_win_sta:�(rps_s,�rps_s)�->�bool
fun{}�rps_win_s
��{r1:rps_s}�(x:�rps_t�(r1)):
��[r2:rps_s�│�rps_win_sta�(r2,�r1)]�(rps_t�(r2))
stacst�rps_win_sta:�(rps_s,�rps_s)�->�bool
fun{}�rps_win_s
��{r1:rps_s}�(x:�rps_t�(r1)):
��[r2:rps_s�│�rps_win_sta�(r2,�r1)]�(rps_t�(r2))
stacst�rps_win_sta:�(rps_s,�rps_s)�->�bool
fun{}�rps_win_s
��{r1:rps_s}�(x:�rps_t�(r1)):
��[r2:rps_s�│�rps_win_sta�(r2,�r1)]�(rps_t�(r2))
stacst�rps_win_sta:�(rps_s,�rps_s)�->�bool
fun{}�rps_win_s
��{r1:rps_s}�(x:�rps_t�(r1)):
��[r2:rps_s�│�rps_win_sta�(r2,�r1)]�(rps_t�(r2))
stacst�rps_win_sta:�(rps_s,�rps_s)�->�bool
fun{}�rps_win_s
��{r1:rps_s}�(x:�rps_t�(r1)):
��[r2:rps_s�│�rps_win_sta�(r2,�r1)]�(rps_t�(r2))
Implementation using Statics of ATSImplementation using Statics of ATSImplementation using Statics of ATSImplementation using Statics of ATSImplementation using Statics of ATS
extern�praxi�rps_win_r_s_pf�():�[rps_win_sta(r_rps_s,�s_rps_s)]�void�(*�
Spec:�Paper�wins�Rock�*)
extern�praxi�rps_win_p_r_pf�():�[rps_win_sta(p_rps_s,�r_rps_s)]�void�(*�
Spec:�Scissors�win�Paper�*)
extern�praxi�rps_win_s_p_pf�():�[rps_win_sta(s_rps_s,�p_rps_s)]�void�(*�
Spec:�Rock�wins�Scissors�*)
implement{}�rps_win_s�(x)�=�let
��prval�()�=�rps_win_r_s_pf()�(*�Introduce�specification�*)
��prval�()�=�rps_win_p_r_pf()
��prval�()�=�rps_win_s_p_pf()
in
��case+�x�of
��│�r_rps_t()�=>�p_rps_t()
��│�p_rps_t()�=>�s_rps_t()
��│�s_rps_t()�=>�r_rps_t()
end
extern�praxi�rps_win_r_s_pf�():�[rps_win_sta(r_rps_s,�s_rps_s)]�void�(*�
Spec:�Paper�wins�Rock�*)
extern�praxi�rps_win_p_r_pf�():�[rps_win_sta(p_rps_s,�r_rps_s)]�void�(*�
Spec:�Scissors�win�Paper�*)
extern�praxi�rps_win_s_p_pf�():�[rps_win_sta(s_rps_s,�p_rps_s)]�void�(*�
Spec:�Rock�wins�Scissors�*)
implement{}�rps_win_s�(x)�=�let
��prval�()�=�rps_win_r_s_pf()�(*�Introduce�specification�*)
��prval�()�=�rps_win_p_r_pf()
��prval�()�=�rps_win_s_p_pf()
in
��case+�x�of
��│�r_rps_t()�=>�p_rps_t()
��│�p_rps_t()�=>�s_rps_t()
��│�s_rps_t()�=>�r_rps_t()
end
extern�praxi�rps_win_r_s_pf�():�[rps_win_sta(r_rps_s,�s_rps_s)]�void�(*�
Spec:�Paper�wins�Rock�*)
extern�praxi�rps_win_p_r_pf�():�[rps_win_sta(p_rps_s,�r_rps_s)]�void�(*�
Spec:�Scissors�win�Paper�*)
extern�praxi�rps_win_s_p_pf�():�[rps_win_sta(s_rps_s,�p_rps_s)]�void�(*�
Spec:�Rock�wins�Scissors�*)
implement{}�rps_win_s�(x)�=�let
��prval�()�=�rps_win_r_s_pf()�(*�Introduce�specification�*)
��prval�()�=�rps_win_p_r_pf()
��prval�()�=�rps_win_s_p_pf()
in
��case+�x�of
��│�r_rps_t()�=>�p_rps_t()
��│�p_rps_t()�=>�s_rps_t()
��│�s_rps_t()�=>�r_rps_t()
end
extern�praxi�rps_win_r_s_pf�():�[rps_win_sta(r_rps_s,�s_rps_s)]�void�(*�
Spec:�Paper�wins�Rock�*)
extern�praxi�rps_win_p_r_pf�():�[rps_win_sta(p_rps_s,�r_rps_s)]�void�(*�
Spec:�Scissors�win�Paper�*)
extern�praxi�rps_win_s_p_pf�():�[rps_win_sta(s_rps_s,�p_rps_s)]�void�(*�
Spec:�Rock�wins�Scissors�*)
implement{}�rps_win_s�(x)�=�let
��prval�()�=�rps_win_r_s_pf()�(*�Introduce�specification�*)
��prval�()�=�rps_win_p_r_pf()
��prval�()�=�rps_win_s_p_pf()
in
��case+�x�of
��│�r_rps_t()�=>�p_rps_t()
��│�p_rps_t()�=>�s_rps_t()
��│�s_rps_t()�=>�r_rps_t()
end
extern praxi�rps_win_r_s_pf�():�[rps_win_sta(r_rps_s,�s_rps_s)]�void�(*�
Spec:�Paper�wins�Rock�*)
extern praxi�rps_win_p_r_pf�():�[rps_win_sta(p_rps_s,�r_rps_s)]�void�(*�
Spec:�Scissors�win�Paper�*)
extern praxi�rps_win_s_p_pf�():�[rps_win_sta(s_rps_s,�p_rps_s)]�void�(*�
Spec:�Rock�wins�Scissors�*)
implement{}�rps_win_s�(x)�=�let
prval�()�=�rps_win_r_s_pf()�(*�Introduce�specification�*)
prval�()�=�rps_win_p_r_pf()
prval�()�=�rps_win_s_p_pf()
in
��case+�x�of
��│�r_rps_t()�=>�p_rps_t()
��│�p_rps_t()�=>�s_rps_t()
��│�s_rps_t()�=>�r_rps_t()
end
Statics can catch error at compile-timeStatics can catch error at compile-timeStatics can catch error at compile-timeStatics can catch error at compile-timeStatics can catch error at compile-time
implement{}�rps_win_s�(x)�=�let
��prval�()�=�rps_win_r_s_pf()�(*�Introduce�specification�*)
��prval�()�=�rps_win_p_r_pf()
��prval�()�=�rps_win_s_p_pf()
in
��case+�x�of
��│�r_rps_t()�=>�r_rps_t()�(*�Compile-time�error!�*)
��│�p_rps_t()�=>�s_rps_t()
��│�s_rps_t()�=>�r_rps_t()
end
implement{}�rps_win_s�(x)�=�let
��prval�()�=�rps_win_r_s_pf()�(*�Introduce�specification�*)
��prval�()�=�rps_win_p_r_pf()
��prval�()�=�rps_win_s_p_pf()
in
��case+�x�of
��│�r_rps_t()�=>�r_rps_t()�(*�Compile-time�error!�*)
��│�p_rps_t()�=>�s_rps_t()
��│�s_rps_t()�=>�r_rps_t()
end
implement{}�rps_win_s�(x)�=�let
��prval�()�=�rps_win_r_s_pf()�(*�Introduce�specification�*)
��prval�()�=�rps_win_p_r_pf()
��prval�()�=�rps_win_s_p_pf()
in
��case+�x�of
��│�r_rps_t()�=>�r_rps_t()�(*�Compile-time�error!�*)
��│�p_rps_t()�=>�s_rps_t()
��│�s_rps_t()�=>�r_rps_t()
end
implement{}�rps_win_s�(x)�=�let
��prval�()�=�rps_win_r_s_pf()�(*�Introduce�specification�*)
��prval�()�=�rps_win_p_r_pf()
��prval�()�=�rps_win_s_p_pf()
in
��case+�x�of
��│�r_rps_t()�=>�r_rps_t()�(*�Compile-time�error!�*)
��│�p_rps_t()�=>�s_rps_t()
��│�s_rps_t()�=>�r_rps_t()
end
implement{}�rps_win_s�(x)�=�let
prval�()�=�rps_win_r_s_pf()�(*�Introduce�specification�*)
prval�()�=�rps_win_p_r_pf()
prval�()�=�rps_win_s_p_pf()
in
��case+�x�of
��│�r_rps_t()�=>�r_rps_t()�(*�Compile-time�error!�*)
��│�p_rps_t()�=>�s_rps_t()
��│�s_rps_t()�=>�r_rps_t()
end
$�patscc�main.dats�-DATS_MEMALLOC_LIBC
/home/kiwamu/src/practice-ats/static_rps/rps.dats:�933(line=36,�offs=18)�--�
942(line=36,�offs=27):�error(3):�unsolved�constraint:�C3NSTRprop(C3TKmain();�
S2Eapp(S2Ecst(rps_win_sta);�S2EVar(4434->S2Eapp(S2Ecst(r_rps_s);�)),�S2Evar
(r1$2870(7929))))
$�patscc�main.dats�-DATS_MEMALLOC_LIBC
/home/kiwamu/src/practice-ats/static_rps/rps.dats:�933(line=36,�offs=18)�--�
942(line=36,�offs=27):�error(3):�unsolved�constraint:�C3NSTRprop(C3TKmain();�
S2Eapp(S2Ecst(rps_win_sta);�S2EVar(4434->S2Eapp(S2Ecst(r_rps_s);�)),�S2Evar
(r1$2870(7929))))
$�patscc�main.dats�-DATS_MEMALLOC_LIBC
/home/kiwamu/src/practice-ats/static_rps/rps.dats:�933(line=36,�offs=18)�--�
942(line=36,�offs=27):�error(3):�unsolved�constraint:�C3NSTRprop(C3TKmain();�
S2Eapp(S2Ecst(rps_win_sta);�S2EVar(4434->S2Eapp(S2Ecst(r_rps_s);�)),�S2Evar
(r1$2870(7929))))
$�patscc�main.dats�-DATS_MEMALLOC_LIBC
/home/kiwamu/src/practice-ats/static_rps/rps.dats:�933(line=36,�offs=18)�--�
942(line=36,�offs=27):�error(3):�unsolved�constraint:�C3NSTRprop(C3TKmain();�
S2Eapp(S2Ecst(rps_win_sta);�S2EVar(4434->S2Eapp(S2Ecst(r_rps_s);�)),�S2Evar
(r1$2870(7929))))
$�patscc�main.dats�-DATS_MEMALLOC_LIBC
/home/kiwamu/src/practice-ats/static_rps/rps.dats:�933(line=36,�offs=18)�--�
942(line=36,�offs=27):�error(3):�unsolved�constraint:�C3NSTRprop(C3TKmain();�
S2Eapp(S2Ecst(rps_win_sta);�S2EVar(4434->S2Eapp(S2Ecst(r_rps_s);�)),�S2Evar
(r1$2870(7929))))
Specification using Proofs of ATSSpecification using Proofs of ATSSpecification using Proofs of ATSSpecification using Proofs of ATSSpecification using Proofs of ATS
dataprop�RPS_WIN�(rps_s,�rps_s)�=
��│�RPS_P_WIN_R�(p_rps_s,�r_rps_s)�(*�Spec:�Paper�wins�Rock�*)
��│�RPS_S_WIN_P�(s_rps_s,�p_rps_s)�(*�Spec:�Scissors�win�Paper�*)
��│�RPS_R_WIN_S�(r_rps_s,�s_rps_s)�(*�Spec:�Rock�wins�Scissors�*)
fun{}�rps_win_p
��{r1:rps_s}�(x:�rps_t�(r1)):
��[r2:rps_s]�(RPS_WIN�(r2,�r1)�│�rps_t�(r2))
dataprop�RPS_WIN�(rps_s,�rps_s)�=
��│�RPS_P_WIN_R�(p_rps_s,�r_rps_s)�(*�Spec:�Paper�wins�Rock�*)
��│�RPS_S_WIN_P�(s_rps_s,�p_rps_s)�(*�Spec:�Scissors�win�Paper�*)
��│�RPS_R_WIN_S�(r_rps_s,�s_rps_s)�(*�Spec:�Rock�wins�Scissors�*)
fun{}�rps_win_p
��{r1:rps_s}�(x:�rps_t�(r1)):
��[r2:rps_s]�(RPS_WIN�(r2,�r1)�│�rps_t�(r2))
dataprop�RPS_WIN�(rps_s,�rps_s)�=
��│�RPS_P_WIN_R�(p_rps_s,�r_rps_s)�(*�Spec:�Paper�wins�Rock�*)
��│�RPS_S_WIN_P�(s_rps_s,�p_rps_s)�(*�Spec:�Scissors�win�Paper�*)
��│�RPS_R_WIN_S�(r_rps_s,�s_rps_s)�(*�Spec:�Rock�wins�Scissors�*)
fun{}�rps_win_p
��{r1:rps_s}�(x:�rps_t�(r1)):
��[r2:rps_s]�(RPS_WIN�(r2,�r1)�│�rps_t�(r2))
dataprop�RPS_WIN�(rps_s,�rps_s)�=
��│�RPS_P_WIN_R�(p_rps_s,�r_rps_s)�(*�Spec:�Paper�wins�Rock�*)
��│�RPS_S_WIN_P�(s_rps_s,�p_rps_s)�(*�Spec:�Scissors�win�Paper�*)
��│�RPS_R_WIN_S�(r_rps_s,�s_rps_s)�(*�Spec:�Rock�wins�Scissors�*)
fun{}�rps_win_p
��{r1:rps_s}�(x:�rps_t�(r1)):
��[r2:rps_s]�(RPS_WIN�(r2,�r1)�│�rps_t�(r2))
dataprop�RPS_WIN�(rps_s,�rps_s)�=
��│�RPS_P_WIN_R�(p_rps_s,�r_rps_s)�(*�Spec:�Paper�wins�Rock�*)
��│�RPS_S_WIN_P�(s_rps_s,�p_rps_s)�(*�Spec:�Scissors�win�Paper�*)
��│�RPS_R_WIN_S�(r_rps_s,�s_rps_s)�(*�Spec:�Rock�wins�Scissors�*)
fun{}�rps_win_p
��{r1:rps_s}�(x:�rps_t�(r1)):
��[r2:rps_s]�(RPS_WIN�(r2,�r1)�│�rps_t�(r2))
Implementation using Proofs of ATSImplementation using Proofs of ATSImplementation using Proofs of ATSImplementation using Proofs of ATSImplementation using Proofs of ATS
implement{}�rps_win_p�(x)�=�case+�x�of
��│�r_rps_t()�=>�(RPS_P_WIN_R()�│�p_rps_t())
��│�p_rps_t()�=>�(RPS_S_WIN_P()�│�s_rps_t())
��│�s_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())
implement{}�rps_win_p�(x)�=�case+�x�of
��│�r_rps_t()�=>�(RPS_P_WIN_R()�│�p_rps_t())
��│�p_rps_t()�=>�(RPS_S_WIN_P()�│�s_rps_t())
��│�s_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())
implement{}�rps_win_p�(x)�=�case+�x�of
��│�r_rps_t()�=>�(RPS_P_WIN_R()�│�p_rps_t())
��│�p_rps_t()�=>�(RPS_S_WIN_P()�│�s_rps_t())
��│�s_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())
implement{}�rps_win_p�(x)�=�case+�x�of
��│�r_rps_t()�=>�(RPS_P_WIN_R()�│�p_rps_t())
��│�p_rps_t()�=>�(RPS_S_WIN_P()�│�s_rps_t())
��│�s_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())
implement{}�rps_win_p�(x)�=�case+�x�of
��│�r_rps_t()�=>�(RPS_P_WIN_R()�│�p_rps_t())
��│�p_rps_t()�=>�(RPS_S_WIN_P()�│�s_rps_t())
��│�s_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())
Proofs can catch error at compile-timeProofs can catch error at compile-timeProofs can catch error at compile-timeProofs can catch error at compile-timeProofs can catch error at compile-time
implement{}�rps_win_p�(x)�=�case+�x�of
��│�r_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())�(*�Compile-time�error!�*)
��│�p_rps_t()�=>�(RPS_S_WIN_P()�│�s_rps_t())
��│�s_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())
implement{}�rps_win_p�(x)�=�case+�x�of
��│�r_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())�(*�Compile-time�error!�*)
��│�p_rps_t()�=>�(RPS_S_WIN_P()�│�s_rps_t())
��│�s_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())
implement{}�rps_win_p�(x)�=�case+�x�of
��│�r_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())�(*�Compile-time�error!�*)
��│�p_rps_t()�=>�(RPS_S_WIN_P()�│�s_rps_t())
��│�s_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())
implement{}�rps_win_p�(x)�=�case+�x�of
��│�r_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())�(*�Compile-time�error!�*)
��│�p_rps_t()�=>�(RPS_S_WIN_P()�│�s_rps_t())
��│�s_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())
implement{}�rps_win_p�(x)�=�case+�x�of
��│�r_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())�(*�Compile-time�error!�*)
��│�p_rps_t()�=>�(RPS_S_WIN_P()�│�s_rps_t())
��│�s_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())
$�patscc�main.dats�-DATS_MEMALLOC_LIBC
/home/kiwamu/src/practice-ats/static_rps/rps.dats:�1199(line=45,�offs=18)�--�
1226(line=45,�offs=45):�error(3):�the�dynamic�expression�cannot�be�assigned�
the�type�[S2Eexi(r2$2876(7935);�;�S2Etyrec(flt0;�npf=1;�0=S2Eapp(S2Ecst
(RPS_WIN);�S2Evar(r2$2876(7935)),�S2Evar(r1$2875(7934))),�1=S2Eapp(S2Ecst
(rps_t);�S2Evar(r2$2876(7935)))))].
$�patscc�main.dats�-DATS_MEMALLOC_LIBC
/home/kiwamu/src/practice-ats/static_rps/rps.dats:�1199(line=45,�offs=18)�--�
1226(line=45,�offs=45):�error(3):�the�dynamic�expression�cannot�be�assigned�
the�type�[S2Eexi(r2$2876(7935);�;�S2Etyrec(flt0;�npf=1;�0=S2Eapp(S2Ecst
(RPS_WIN);�S2Evar(r2$2876(7935)),�S2Evar(r1$2875(7934))),�1=S2Eapp(S2Ecst
(rps_t);�S2Evar(r2$2876(7935)))))].
$�patscc�main.dats�-DATS_MEMALLOC_LIBC
/home/kiwamu/src/practice-ats/static_rps/rps.dats:�1199(line=45,�offs=18)�--�
1226(line=45,�offs=45):�error(3):�the�dynamic�expression�cannot�be�assigned�
the�type�[S2Eexi(r2$2876(7935);�;�S2Etyrec(flt0;�npf=1;�0=S2Eapp(S2Ecst
(RPS_WIN);�S2Evar(r2$2876(7935)),�S2Evar(r1$2875(7934))),�1=S2Eapp(S2Ecst
(rps_t);�S2Evar(r2$2876(7935)))))].
$�patscc�main.dats�-DATS_MEMALLOC_LIBC
/home/kiwamu/src/practice-ats/static_rps/rps.dats:�1199(line=45,�offs=18)�--�
1226(line=45,�offs=45):�error(3):�the�dynamic�expression�cannot�be�assigned�
the�type�[S2Eexi(r2$2876(7935);�;�S2Etyrec(flt0;�npf=1;�0=S2Eapp(S2Ecst
(RPS_WIN);�S2Evar(r2$2876(7935)),�S2Evar(r1$2875(7934))),�1=S2Eapp(S2Ecst
(rps_t);�S2Evar(r2$2876(7935)))))].
$�patscc�main.dats�-DATS_MEMALLOC_LIBC
/home/kiwamu/src/practice-ats/static_rps/rps.dats:�1199(line=45,�offs=18)�--�
1226(line=45,�offs=45):�error(3):�the�dynamic�expression�cannot�be�assigned�
the�type�[S2Eexi(r2$2876(7935);�;�S2Etyrec(flt0;�npf=1;�0=S2Eapp(S2Ecst
(RPS_WIN);�S2Evar(r2$2876(7935)),�S2Evar(r1$2875(7934))),�1=S2Eapp(S2Ecst
(rps_t);�S2Evar(r2$2876(7935)))))].
The code is found at GitHubThe code is found at GitHubThe code is found at GitHubThe code is found at GitHubThe code is found at GitHub
https://github.com/jats-ug/practice-ats/tree/master/static_rpshttps://github.com/jats-ug/practice-ats/tree/master/static_rpshttps://github.com/jats-ug/practice-ats/tree/master/static_rpshttps://github.com/jats-ug/practice-ats/tree/master/static_rpshttps://github.com/jats-ug/practice-ats/tree/master/static_rps
License of photosLicense of photosLicense of photosLicense of photosLicense of photos
*�A�chart�showing�how�the�three�game�elements�of�"Rock-paper-scissors"�
interact.
��https://en.wikipedia.org/wiki/Rock-paper-scissors#/media/File:Rock-paper-
scissors.svg
��Copyright:�Antonsusi�/�License:�CC�BY-SA�3.0
*�Scissors�Rock�Paper�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/zombiesquirrels/3477986919/
��Copyright:�Mike�Souza�/�License:�CC�BY-SA�2.0
*�AKB48�34th�Single�Selection�Rock,�Paper,�Scissors�Tournament:�
Advertisement�at�Shibuya�Station�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/31029865@N06/15018892358/
��Copyright:�Dick�Thomas�Johnson�/�License:�CC�BY�2.0
*�Cuddle�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/peptravassos/14206994372/
��Copyright:�Pedro�Travassos�/�License:�CC�BY�2.0
*�Corey�Donohoe�(GitHub):�Metrics�Driven�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/stevelacey/5820920545/
��Copyright:�Steve�Lacey�/�License:�CC�BY�2.0
*�Imagine�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/tonythemisfit/4773974792/
��Copyright:�Tony�Fischer�/�License:�CC�BY�2.0
*�Creative�Commons�BBB�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/steren/2732488224/
��Copyright:�Steren�Giannini�/�License:�CC�BY�2.0
*�A�chart�showing�how�the�three�game�elements�of�"Rock-paper-scissors"�
interact.
��https://en.wikipedia.org/wiki/Rock-paper-scissors#/media/File:Rock-paper-
scissors.svg
��Copyright:�Antonsusi�/�License:�CC�BY-SA�3.0
*�Scissors�Rock�Paper�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/zombiesquirrels/3477986919/
��Copyright:�Mike�Souza�/�License:�CC�BY-SA�2.0
*�AKB48�34th�Single�Selection�Rock,�Paper,�Scissors�Tournament:�
Advertisement�at�Shibuya�Station�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/31029865@N06/15018892358/
��Copyright:�Dick�Thomas�Johnson�/�License:�CC�BY�2.0
*�Cuddle�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/peptravassos/14206994372/
��Copyright:�Pedro�Travassos�/�License:�CC�BY�2.0
*�Corey�Donohoe�(GitHub):�Metrics�Driven�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/stevelacey/5820920545/
��Copyright:�Steve�Lacey�/�License:�CC�BY�2.0
*�Imagine�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/tonythemisfit/4773974792/
��Copyright:�Tony�Fischer�/�License:�CC�BY�2.0
*�Creative�Commons�BBB�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/steren/2732488224/
��Copyright:�Steren�Giannini�/�License:�CC�BY�2.0
*�A�chart�showing�how�the�three�game�elements�of�"Rock-paper-scissors"�
interact.
��https://en.wikipedia.org/wiki/Rock-paper-scissors#/media/File:Rock-paper-
scissors.svg
��Copyright:�Antonsusi�/�License:�CC�BY-SA�3.0
*�Scissors�Rock�Paper�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/zombiesquirrels/3477986919/
��Copyright:�Mike�Souza�/�License:�CC�BY-SA�2.0
*�AKB48�34th�Single�Selection�Rock,�Paper,�Scissors�Tournament:�
Advertisement�at�Shibuya�Station�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/31029865@N06/15018892358/
��Copyright:�Dick�Thomas�Johnson�/�License:�CC�BY�2.0
*�Cuddle�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/peptravassos/14206994372/
��Copyright:�Pedro�Travassos�/�License:�CC�BY�2.0
*�Corey�Donohoe�(GitHub):�Metrics�Driven�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/stevelacey/5820920545/
��Copyright:�Steve�Lacey�/�License:�CC�BY�2.0
*�Imagine�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/tonythemisfit/4773974792/
��Copyright:�Tony�Fischer�/�License:�CC�BY�2.0
*�Creative�Commons�BBB�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/steren/2732488224/
��Copyright:�Steren�Giannini�/�License:�CC�BY�2.0
*�A�chart�showing�how�the�three�game�elements�of�"Rock-paper-scissors"�
interact.
��https://en.wikipedia.org/wiki/Rock-paper-scissors#/media/File:Rock-paper-
scissors.svg
��Copyright:�Antonsusi�/�License:�CC�BY-SA�3.0
*�Scissors�Rock�Paper�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/zombiesquirrels/3477986919/
��Copyright:�Mike�Souza�/�License:�CC�BY-SA�2.0
*�AKB48�34th�Single�Selection�Rock,�Paper,�Scissors�Tournament:�
Advertisement�at�Shibuya�Station�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/31029865@N06/15018892358/
��Copyright:�Dick�Thomas�Johnson�/�License:�CC�BY�2.0
*�Cuddle�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/peptravassos/14206994372/
��Copyright:�Pedro�Travassos�/�License:�CC�BY�2.0
*�Corey�Donohoe�(GitHub):�Metrics�Driven�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/stevelacey/5820920545/
��Copyright:�Steve�Lacey�/�License:�CC�BY�2.0
*�Imagine�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/tonythemisfit/4773974792/
��Copyright:�Tony�Fischer�/�License:�CC�BY�2.0
*�Creative�Commons�BBB�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/steren/2732488224/
��Copyright:�Steren�Giannini�/�License:�CC�BY�2.0
*�A�chart�showing�how�the�three�game�elements�of�"Rock-paper-scissors"�
interact.
��https://en.wikipedia.org/wiki/Rock-paper-scissors#/media/File:Rock-paper-
scissors.svg
��Copyright:�Antonsusi�/�License:�CC�BY-SA�3.0
*�Scissors�Rock�Paper�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/zombiesquirrels/3477986919/
��Copyright:�Mike�Souza�/�License:�CC�BY-SA�2.0
*�AKB48�34th�Single�Selection�Rock,�Paper,�Scissors�Tournament:�
Advertisement�at�Shibuya�Station�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/31029865@N06/15018892358/
��Copyright:�Dick�Thomas�Johnson�/�License:�CC�BY�2.0
*�Cuddle�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/peptravassos/14206994372/
��Copyright:�Pedro�Travassos�/�License:�CC�BY�2.0
*�Corey�Donohoe�(GitHub):�Metrics�Driven�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/stevelacey/5820920545/
��Copyright:�Steve�Lacey�/�License:�CC�BY�2.0
*�Imagine�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/tonythemisfit/4773974792/
��Copyright:�Tony�Fischer�/�License:�CC�BY�2.0
*�Creative�Commons�BBB�│�Flickr�-�Photo�Sharing!
��https://www.flickr.com/photos/steren/2732488224/
��Copyright:�Steren�Giannini�/�License:�CC�BY�2.0

Static typing and proof in ATS language

  • 1.
    Static typing andproof in ATS language Static typing and proof in ATS language Static typing and proof in ATS language Static typing and proof in ATS language Static typing and proof in ATS language Kiwamu OkabeKiwamu OkabeKiwamu OkabeKiwamu OkabeKiwamu Okabe
  • 2.
    Let's make Rock-paper-scissorslibraryLet's make Rock-paper-scissors libraryLet's make Rock-paper-scissors libraryLet's make Rock-paper-scissors libraryLet's make Rock-paper-scissors library ☆ �じゃんけん� in Japanese.☆ �じゃんけん� in Japanese.☆ �じゃんけん� in Japanese.☆ �じゃんけん� in Japanese.☆ �じゃんけん� in Japanese.
  • 3.
    R-P-S in Clanguage #1R-P-S in C language #1R-P-S in C language #1R-P-S in C language #1R-P-S in C language #1 #include�<stdio.h> #include�<stdlib.h> typedef�enum�{ R_RPS_T�=�0,�/*�Rock�*/ P_RPS_T,�����/*�Paper�*/ S_RPS_T������/*�Scissors�*/ }�rps_t; void�print_rps(rps_t�x)�{ switch�(x)�{ case�R_RPS_T: printf("Rock");�break; case�P_RPS_T: printf("Paper");�break; case�S_RPS_T: printf("Scissors");�break; } } #include�<stdio.h> #include�<stdlib.h> typedef�enum�{ R_RPS_T�=�0,�/*�Rock�*/ P_RPS_T,�����/*�Paper�*/ S_RPS_T������/*�Scissors�*/ }�rps_t; void�print_rps(rps_t�x)�{ switch�(x)�{ case�R_RPS_T: printf("Rock");�break; case�P_RPS_T: printf("Paper");�break; case�S_RPS_T: printf("Scissors");�break; } } #include�<stdio.h> #include�<stdlib.h> typedef�enum�{ R_RPS_T�=�0,�/*�Rock�*/ P_RPS_T,�����/*�Paper�*/ S_RPS_T������/*�Scissors�*/ }�rps_t; void�print_rps(rps_t�x)�{ switch�(x)�{ case�R_RPS_T: printf("Rock");�break; case�P_RPS_T: printf("Paper");�break; case�S_RPS_T: printf("Scissors");�break; } } #include�<stdio.h> #include�<stdlib.h> typedef�enum�{ R_RPS_T�=�0,�/*�Rock�*/ P_RPS_T,�����/*�Paper�*/ S_RPS_T������/*�Scissors�*/ }�rps_t; void�print_rps(rps_t�x)�{ switch�(x)�{ case�R_RPS_T: printf("Rock");�break; case�P_RPS_T: printf("Paper");�break; case�S_RPS_T: printf("Scissors");�break; } } #include�<stdio.h> #include�<stdlib.h> typedef enum�{ R_RPS_T�=�0,�/*�Rock�*/ P_RPS_T,�����/*�Paper�*/ S_RPS_T������/*�Scissors�*/ }�rps_t; void�print_rps(rps_t�x)�{ switch�(x)�{ case�R_RPS_T: printf("Rock");�break; case�P_RPS_T: printf("Paper");�break; case�S_RPS_T: printf("Scissors");�break; } }
  • 4.
    R-P-S in Clanguage #2R-P-S in C language #2R-P-S in C language #2R-P-S in C language #2R-P-S in C language #2 int�main()�{ rps_t�paper_d�=�P_RPS_T; rps_t�win_d�=�rps_win_d�(paper_d); print_rps(win_d);�printf("�win�");�print_rps(paper_d);�printf(".n"); /*�=>�Scissors�win�Paper.�*/ rps_t�even_d�=�rps_even_d(win_d,�paper_d); print_rps(even_d);�printf("�is�even�between�");�print_rps(win_d); printf("�and�");�print_rps(paper_d);�printf(".n"); /*�=>�Rock�is�even�between�Scissors�and�Paper.�*/ } int�main()�{ rps_t�paper_d�=�P_RPS_T; rps_t�win_d�=�rps_win_d�(paper_d); print_rps(win_d);�printf("�win�");�print_rps(paper_d);�printf(".n"); /*�=>�Scissors�win�Paper.�*/ rps_t�even_d�=�rps_even_d(win_d,�paper_d); print_rps(even_d);�printf("�is�even�between�");�print_rps(win_d); printf("�and�");�print_rps(paper_d);�printf(".n"); /*�=>�Rock�is�even�between�Scissors�and�Paper.�*/ } int�main()�{ rps_t�paper_d�=�P_RPS_T; rps_t�win_d�=�rps_win_d�(paper_d); print_rps(win_d);�printf("�win�");�print_rps(paper_d);�printf(".n"); /*�=>�Scissors�win�Paper.�*/ rps_t�even_d�=�rps_even_d(win_d,�paper_d); print_rps(even_d);�printf("�is�even�between�");�print_rps(win_d); printf("�and�");�print_rps(paper_d);�printf(".n"); /*�=>�Rock�is�even�between�Scissors�and�Paper.�*/ } int�main()�{ rps_t�paper_d�=�P_RPS_T; rps_t�win_d�=�rps_win_d�(paper_d); print_rps(win_d);�printf("�win�");�print_rps(paper_d);�printf(".n"); /*�=>�Scissors�win�Paper.�*/ rps_t�even_d�=�rps_even_d(win_d,�paper_d); print_rps(even_d);�printf("�is�even�between�");�print_rps(win_d); printf("�and�");�print_rps(paper_d);�printf(".n"); /*�=>�Rock�is�even�between�Scissors�and�Paper.�*/ } int�main()�{ rps_t�paper_d�=�P_RPS_T; rps_t�win_d�=�rps_win_d�(paper_d); print_rps(win_d);�printf("�win�");�print_rps(paper_d);�printf(".n"); /*�=>�Scissors�win�Paper.�*/ rps_t�even_d�=�rps_even_d(win_d,�paper_d); print_rps(even_d);�printf("�is�even�between�");�print_rps(win_d); printf("�and�");�print_rps(paper_d);�printf(".n"); /*�=>�Rock�is�even�between�Scissors�and�Paper.�*/ }
  • 5.
    R-P-S in Clanguage #3R-P-S in C language #3R-P-S in C language #3R-P-S in C language #3R-P-S in C language #3 rps_t�rps_win_d(rps_t�x)�{ switch�(x)�{ case�R_RPS_T: return�P_RPS_T; case�P_RPS_T: return�S_RPS_T; case�S_RPS_T: return�R_RPS_T; default: abort(); } } #define�PACK(X,Y)�((X)<<4�│�(Y)) rps_t�rps_even_d(rps_t�x,�rps_t�y)�{ switch�(PACK(x,�y))�{ case�PACK(P_RPS_T,�R_RPS_T): case�PACK(S_RPS_T,�P_RPS_T): case�PACK(R_RPS_T,�S_RPS_T): return�rps_win_d(x); default: abort(); } } rps_t�rps_win_d(rps_t�x)�{ switch�(x)�{ case�R_RPS_T: return�P_RPS_T; case�P_RPS_T: return�S_RPS_T; case�S_RPS_T: return�R_RPS_T; default: abort(); } } #define�PACK(X,Y)�((X)<<4�│�(Y)) rps_t�rps_even_d(rps_t�x,�rps_t�y)�{ switch�(PACK(x,�y))�{ case�PACK(P_RPS_T,�R_RPS_T): case�PACK(S_RPS_T,�P_RPS_T): case�PACK(R_RPS_T,�S_RPS_T): return�rps_win_d(x); default: abort(); } } rps_t�rps_win_d(rps_t�x)�{ switch�(x)�{ case�R_RPS_T: return�P_RPS_T; case�P_RPS_T: return�S_RPS_T; case�S_RPS_T: return�R_RPS_T; default: abort(); } } #define�PACK(X,Y)�((X)<<4�│�(Y)) rps_t�rps_even_d(rps_t�x,�rps_t�y)�{ switch�(PACK(x,�y))�{ case�PACK(P_RPS_T,�R_RPS_T): case�PACK(S_RPS_T,�P_RPS_T): case�PACK(R_RPS_T,�S_RPS_T): return�rps_win_d(x); default: abort(); } } rps_t�rps_win_d(rps_t�x)�{ switch�(x)�{ case�R_RPS_T: return�P_RPS_T; case�P_RPS_T: return�S_RPS_T; case�S_RPS_T: return�R_RPS_T; default: abort(); } } #define�PACK(X,Y)�((X)<<4�│�(Y)) rps_t�rps_even_d(rps_t�x,�rps_t�y)�{ switch�(PACK(x,�y))�{ case�PACK(P_RPS_T,�R_RPS_T): case�PACK(S_RPS_T,�P_RPS_T): case�PACK(R_RPS_T,�S_RPS_T): return�rps_win_d(x); default: abort(); } } rps_t�rps_win_d(rps_t�x)�{ switch�(x)�{ case�R_RPS_T: return�P_RPS_T; case�P_RPS_T: return�S_RPS_T; case�S_RPS_T: return�R_RPS_T; default: abort(); } } #define�PACK(X,Y)�((X)<<4�│�(Y)) rps_t�rps_even_d(rps_t�x,�rps_t�y)�{ switch�(PACK(x,�y))�{ case�PACK(P_RPS_T,�R_RPS_T): case�PACK(S_RPS_T,�P_RPS_T): case�PACK(R_RPS_T,�S_RPS_T): return�rps_win_d(x); default: abort(); } }
  • 6.
    However you canmake run-time errorHowever you can make run-time errorHowever you can make run-time errorHowever you can make run-time errorHowever you can make run-time error rps_t�rps_win_d(rps_t�x)�{ switch�(x)�{ case�R_RPS_T: return�R_RPS_T;�/*�Run-time�error!�*/ case�P_RPS_T: return�S_RPS_T; /* case�S_RPS_T: return�R_RPS_T;�*/�/*�Not�exhaustive!�*/ default: abort();�/*�Abort�occurs!�*/ } } #define�PACK(X,Y)�((X)<<4�│�(Y)) rps_t�rps_even_d(rps_t�x,�rps_t�y)�{ switch�(PACK(x,�y))�{ case�PACK(P_RPS_T,�R_RPS_T): case�PACK(S_RPS_T,�P_RPS_T): case�PACK(R_RPS_T,�S_RPS_T): return�rps_win_d(y);�/*�Run-time�error!�*/ default: abort();�/*�Abort�occurs!�*/ } } rps_t�rps_win_d(rps_t�x)�{ switch�(x)�{ case�R_RPS_T: return�R_RPS_T;�/*�Run-time�error!�*/ case�P_RPS_T: return�S_RPS_T; /* case�S_RPS_T: return�R_RPS_T;�*/�/*�Not�exhaustive!�*/ default: abort();�/*�Abort�occurs!�*/ } } #define�PACK(X,Y)�((X)<<4�│�(Y)) rps_t�rps_even_d(rps_t�x,�rps_t�y)�{ switch�(PACK(x,�y))�{ case�PACK(P_RPS_T,�R_RPS_T): case�PACK(S_RPS_T,�P_RPS_T): case�PACK(R_RPS_T,�S_RPS_T): return�rps_win_d(y);�/*�Run-time�error!�*/ default: abort();�/*�Abort�occurs!�*/ } } rps_t�rps_win_d(rps_t�x)�{ switch�(x)�{ case�R_RPS_T: return�R_RPS_T;�/*�Run-time�error!�*/ case�P_RPS_T: return�S_RPS_T; /* case�S_RPS_T: return�R_RPS_T;�*/�/*�Not�exhaustive!�*/ default: abort();�/*�Abort�occurs!�*/ } } #define�PACK(X,Y)�((X)<<4�│�(Y)) rps_t�rps_even_d(rps_t�x,�rps_t�y)�{ switch�(PACK(x,�y))�{ case�PACK(P_RPS_T,�R_RPS_T): case�PACK(S_RPS_T,�P_RPS_T): case�PACK(R_RPS_T,�S_RPS_T): return�rps_win_d(y);�/*�Run-time�error!�*/ default: abort();�/*�Abort�occurs!�*/ } } rps_t�rps_win_d(rps_t�x)�{ switch�(x)�{ case�R_RPS_T: return�R_RPS_T;�/*�Run-time�error!�*/ case�P_RPS_T: return�S_RPS_T; /* case�S_RPS_T: return�R_RPS_T;�*/�/*�Not�exhaustive!�*/ default: abort();�/*�Abort�occurs!�*/ } } #define�PACK(X,Y)�((X)<<4�│�(Y)) rps_t�rps_even_d(rps_t�x,�rps_t�y)�{ switch�(PACK(x,�y))�{ case�PACK(P_RPS_T,�R_RPS_T): case�PACK(S_RPS_T,�P_RPS_T): case�PACK(R_RPS_T,�S_RPS_T): return�rps_win_d(y);�/*�Run-time�error!�*/ default: abort();�/*�Abort�occurs!�*/ } } rps_t�rps_win_d(rps_t�x)�{ switch�(x)�{ case�R_RPS_T: return�R_RPS_T;�/*�Run-time�error!�*/ case�P_RPS_T: return�S_RPS_T; /* case�S_RPS_T: return�R_RPS_T;�*/ /*�Not�exhaustive!�*/ default: abort();�/*�Abort�occurs!�*/ } } #define�PACK(X,Y)�((X)<<4�│�(Y)) rps_t�rps_even_d(rps_t�x,�rps_t�y)�{ switch�(PACK(x,�y))�{ case�PACK(P_RPS_T,�R_RPS_T): case�PACK(S_RPS_T,�P_RPS_T): case�PACK(R_RPS_T,�S_RPS_T): return�rps_win_d(y);�/*�Run-time�error!�*/ default: abort();�/*�Abort�occurs!�*/ } }
  • 7.
    Please imagine specificationon codePlease imagine specification on codePlease imagine specification on codePlease imagine specification on codePlease imagine specification on code ☆ Introduce specification using static typing.☆ Introduce specification using static typing.☆ Introduce specification using static typing.☆ Introduce specification using static typing.☆ Introduce specification using static typing. ☆ You will get more compile-time errors.☆ You will get more compile-time errors.☆ You will get more compile-time errors.☆ You will get more compile-time errors.☆ You will get more compile-time errors. ☆ You will get less run-time errors.☆ You will get less run-time errors.☆ You will get less run-time errors.☆ You will get less run-time errors.☆ You will get less run-time errors. ☆ You can do that in ATS language.☆ You can do that in ATS language.☆ You can do that in ATS language.☆ You can do that in ATS language.☆ You can do that in ATS language.
  • 8.
    ATS languageATS languageATSlanguageATS 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 More strong type can be used on the ATS.More strong type can be used on the ATS.More strong type can be used on the ATS.More strong type can be used on the ATS.More strong type can be used on the ATS.
  • 9.
    DML-style dependent typesin ATSDML-style dependent types in ATSDML-style dependent types in ATSDML-style dependent types in ATSDML-style dependent types in ATS
  • 10.
    Type of R-P-Sin ATSType of R-P-S in ATSType of R-P-S in ATSType of R-P-S in ATSType of R-P-S in ATS datasort�rps_s�= ��│�r_rps_s�(*�Rock�*) ��│�p_rps_s�(*�Paper�*) ��│�s_rps_s�(*�Scissors�*) datatype�rps_t�(rps_s)�= ��│�r_rps_t�(r_rps_s)�(*�Rock�*) ��│�p_rps_t�(p_rps_s)�(*�Paper�*) ��│�s_rps_t�(s_rps_s)�(*�Scissors�*) typedef�rps_t_any�=�[x:rps_s]�rps_t�(x) datasort�rps_s�= ��│�r_rps_s�(*�Rock�*) ��│�p_rps_s�(*�Paper�*) ��│�s_rps_s�(*�Scissors�*) datatype�rps_t�(rps_s)�= ��│�r_rps_t�(r_rps_s)�(*�Rock�*) ��│�p_rps_t�(p_rps_s)�(*�Paper�*) ��│�s_rps_t�(s_rps_s)�(*�Scissors�*) typedef�rps_t_any�=�[x:rps_s]�rps_t�(x) datasort�rps_s�= ��│�r_rps_s�(*�Rock�*) ��│�p_rps_s�(*�Paper�*) ��│�s_rps_s�(*�Scissors�*) datatype�rps_t�(rps_s)�= ��│�r_rps_t�(r_rps_s)�(*�Rock�*) ��│�p_rps_t�(p_rps_s)�(*�Paper�*) ��│�s_rps_t�(s_rps_s)�(*�Scissors�*) typedef�rps_t_any�=�[x:rps_s]�rps_t�(x) datasort�rps_s�= ��│�r_rps_s�(*�Rock�*) ��│�p_rps_s�(*�Paper�*) ��│�s_rps_s�(*�Scissors�*) datatype�rps_t�(rps_s)�= ��│�r_rps_t�(r_rps_s)�(*�Rock�*) ��│�p_rps_t�(p_rps_s)�(*�Paper�*) ��│�s_rps_t�(s_rps_s)�(*�Scissors�*) typedef�rps_t_any�=�[x:rps_s]�rps_t�(x) datasort�rps_s�= ��│�r_rps_s�(*�Rock�*) ��│�p_rps_s�(*�Paper�*) ��│�s_rps_s�(*�Scissors�*) datatype�rps_t�(rps_s)�= ��│�r_rps_t�(r_rps_s)�(*�Rock�*) ��│�p_rps_t�(p_rps_s)�(*�Paper�*) ��│�s_rps_t�(s_rps_s)�(*�Scissors�*) typedef�rps_t_any�=�[x:rps_s]�rps_t�(x)
  • 11.
    Only use Dynamicsof ATSOnly use Dynamics of ATSOnly use Dynamics of ATSOnly use Dynamics of ATSOnly use Dynamics of ATS fun{}�rps_win_d�(x:�rps_t_any):�rps_t_any fun{}�rps_even_d�(x:�rps_t_any,�y:�rps_t_any):�rps_t_any�(*�The�x�should�win� the�y.�*) implement{}�rps_win_d�(x)�= ��case+�x�of ��│�r_rps_t()�=>�p_rps_t() ��│�p_rps_t()�=>�s_rps_t() ��│�s_rps_t()�=>�r_rps_t() implement{}�rps_even_d�(x,�y)�= ��case+�(x,�y)�of ��│�(p_rps_t(),�r_rps_t())�=>�rps_win_d�(x) ��│�(s_rps_t(),�p_rps_t())�=>�rps_win_d�(x) ��│�(r_rps_t(),�s_rps_t())�=>�rps_win_d�(x) ��│�(_,�_)�=>�$raise�GenerallyExn("The�x�should�win�the�y.") fun{}�rps_win_d�(x:�rps_t_any):�rps_t_any fun{}�rps_even_d�(x:�rps_t_any,�y:�rps_t_any):�rps_t_any�(*�The�x�should�win� the�y.�*) implement{}�rps_win_d�(x)�= ��case+�x�of ��│�r_rps_t()�=>�p_rps_t() ��│�p_rps_t()�=>�s_rps_t() ��│�s_rps_t()�=>�r_rps_t() implement{}�rps_even_d�(x,�y)�= ��case+�(x,�y)�of ��│�(p_rps_t(),�r_rps_t())�=>�rps_win_d�(x) ��│�(s_rps_t(),�p_rps_t())�=>�rps_win_d�(x) ��│�(r_rps_t(),�s_rps_t())�=>�rps_win_d�(x) ��│�(_,�_)�=>�$raise�GenerallyExn("The�x�should�win�the�y.") fun{}�rps_win_d�(x:�rps_t_any):�rps_t_any fun{}�rps_even_d�(x:�rps_t_any,�y:�rps_t_any):�rps_t_any�(*�The�x�should�win� the�y.�*) implement{}�rps_win_d�(x)�= ��case+�x�of ��│�r_rps_t()�=>�p_rps_t() ��│�p_rps_t()�=>�s_rps_t() ��│�s_rps_t()�=>�r_rps_t() implement{}�rps_even_d�(x,�y)�= ��case+�(x,�y)�of ��│�(p_rps_t(),�r_rps_t())�=>�rps_win_d�(x) ��│�(s_rps_t(),�p_rps_t())�=>�rps_win_d�(x) ��│�(r_rps_t(),�s_rps_t())�=>�rps_win_d�(x) ��│�(_,�_)�=>�$raise�GenerallyExn("The�x�should�win�the�y.") fun{}�rps_win_d�(x:�rps_t_any):�rps_t_any fun{}�rps_even_d�(x:�rps_t_any,�y:�rps_t_any):�rps_t_any�(*�The�x�should�win� the�y.�*) implement{}�rps_win_d�(x)�= ��case+�x�of ��│�r_rps_t()�=>�p_rps_t() ��│�p_rps_t()�=>�s_rps_t() ��│�s_rps_t()�=>�r_rps_t() implement{}�rps_even_d�(x,�y)�= ��case+�(x,�y)�of ��│�(p_rps_t(),�r_rps_t())�=>�rps_win_d�(x) ��│�(s_rps_t(),�p_rps_t())�=>�rps_win_d�(x) ��│�(r_rps_t(),�s_rps_t())�=>�rps_win_d�(x) ��│�(_,�_)�=>�$raise�GenerallyExn("The�x�should�win�the�y.") fun{}�rps_win_d�(x:�rps_t_any):�rps_t_any fun{}�rps_even_d�(x:�rps_t_any,�y:�rps_t_any):�rps_t_any�(*�The�x�should�win� the�y.�*) implement{}�rps_win_d�(x)�= ��case+�x�of ��│�r_rps_t()�=>�p_rps_t() ��│�p_rps_t()�=>�s_rps_t() ��│�s_rps_t()�=>�r_rps_t() implement{}�rps_even_d�(x,�y)�= ��case+�(x,�y)�of ��│�(p_rps_t(),�r_rps_t())�=>�rps_win_d�(x) ��│�(s_rps_t(),�p_rps_t())�=>�rps_win_d�(x) ��│�(r_rps_t(),�s_rps_t())�=>�rps_win_d�(x) ��│�(_,�_)�=>�$raise�GenerallyExn("The�x�should�win�the�y.")
  • 12.
    Also you canmake run-time errorAlso you can make run-time errorAlso you can make run-time errorAlso you can make run-time errorAlso you can make run-time error implement{}�rps_win_d�(x)�= ��case+�x�of ��│�r_rps_t()�=>�r_rps_t()�(*�Run-time�error!�*) ��│�p_rps_t()�=>�s_rps_t() (*│�s_rps_t()�=>�r_rps_t()�*)�(*�Compile-time�error!�*) implement{}�rps_even_d�(x,�y)�= ��case+�(x,�y)�of ��│�(p_rps_t(),�r_rps_t())�=>�rps_win_d�(x) ��│�(s_rps_t(),�p_rps_t())�=>�rps_win_d�(y)�(*�Run-time�error!�*) ��│�(r_rps_t(),�s_rps_t())�=>�rps_win_d�(x) ��│�(_,�_)�=>�$raise�GenerallyExn("The�x�should�win�the�y.")�(*�Exception� occurs!�*) implement{}�rps_win_d�(x)�= ��case+�x�of ��│�r_rps_t()�=>�r_rps_t()�(*�Run-time�error!�*) ��│�p_rps_t()�=>�s_rps_t() (*│�s_rps_t()�=>�r_rps_t()�*)�(*�Compile-time�error!�*) implement{}�rps_even_d�(x,�y)�= ��case+�(x,�y)�of ��│�(p_rps_t(),�r_rps_t())�=>�rps_win_d�(x) ��│�(s_rps_t(),�p_rps_t())�=>�rps_win_d�(y)�(*�Run-time�error!�*) ��│�(r_rps_t(),�s_rps_t())�=>�rps_win_d�(x) ��│�(_,�_)�=>�$raise�GenerallyExn("The�x�should�win�the�y.")�(*�Exception� occurs!�*) implement{}�rps_win_d�(x)�= ��case+�x�of ��│�r_rps_t()�=>�r_rps_t()�(*�Run-time�error!�*) ��│�p_rps_t()�=>�s_rps_t() (*│�s_rps_t()�=>�r_rps_t()�*)�(*�Compile-time�error!�*) implement{}�rps_even_d�(x,�y)�= ��case+�(x,�y)�of ��│�(p_rps_t(),�r_rps_t())�=>�rps_win_d�(x) ��│�(s_rps_t(),�p_rps_t())�=>�rps_win_d�(y)�(*�Run-time�error!�*) ��│�(r_rps_t(),�s_rps_t())�=>�rps_win_d�(x) ��│�(_,�_)�=>�$raise�GenerallyExn("The�x�should�win�the�y.")�(*�Exception� occurs!�*) implement{}�rps_win_d�(x)�= ��case+�x�of ��│�r_rps_t()�=>�r_rps_t()�(*�Run-time�error!�*) ��│�p_rps_t()�=>�s_rps_t() (*│�s_rps_t()�=>�r_rps_t()�*)�(*�Compile-time�error!�*) implement{}�rps_even_d�(x,�y)�= ��case+�(x,�y)�of ��│�(p_rps_t(),�r_rps_t())�=>�rps_win_d�(x) ��│�(s_rps_t(),�p_rps_t())�=>�rps_win_d�(y)�(*�Run-time�error!�*) ��│�(r_rps_t(),�s_rps_t())�=>�rps_win_d�(x) ��│�(_,�_)�=>�$raise�GenerallyExn("The�x�should�win�the�y.")�(*�Exception� occurs!�*) implement{}�rps_win_d�(x)�= ��case+�x�of ��│�r_rps_t()�=>�r_rps_t()�(*�Run-time�error!�*) ��│�p_rps_t()�=>�s_rps_t() (*│�s_rps_t()�=>�r_rps_t()�*) (*�Compile-time�error!�*) implement{}�rps_even_d�(x,�y)�= ��case+�(x,�y)�of ��│�(p_rps_t(),�r_rps_t())�=>�rps_win_d�(x) ��│�(s_rps_t(),�p_rps_t())�=>�rps_win_d�(y)�(*�Run-time�error!�*) ��│�(r_rps_t(),�s_rps_t())�=>�rps_win_d�(x) ��│�(_,�_)�=>�$raise�GenerallyExn("The�x�should�win�the�y.")�(*�Exception� occurs!�*) It's caused by having no specification in the implementation. ATS language can have specification as Statics or Proofs. It's caused by having no specification in the implementation. ATS language can have specification as Statics or Proofs. It's caused by having no specification in the implementation. ATS language can have specification as Statics or Proofs. It's caused by having no specification in the implementation. ATS language can have specification as Statics or Proofs. It's caused by having no specification in the implementation. ATS language can have specification as Statics or Proofs.
  • 13.
    Specification using Staticsof ATSSpecification using Statics of ATSSpecification using Statics of ATSSpecification using Statics of ATSSpecification using Statics of ATS stacst�rps_win_sta:�(rps_s,�rps_s)�->�bool fun{}�rps_win_s ��{r1:rps_s}�(x:�rps_t�(r1)): ��[r2:rps_s�│�rps_win_sta�(r2,�r1)]�(rps_t�(r2)) stacst�rps_win_sta:�(rps_s,�rps_s)�->�bool fun{}�rps_win_s ��{r1:rps_s}�(x:�rps_t�(r1)): ��[r2:rps_s�│�rps_win_sta�(r2,�r1)]�(rps_t�(r2)) stacst�rps_win_sta:�(rps_s,�rps_s)�->�bool fun{}�rps_win_s ��{r1:rps_s}�(x:�rps_t�(r1)): ��[r2:rps_s�│�rps_win_sta�(r2,�r1)]�(rps_t�(r2)) stacst�rps_win_sta:�(rps_s,�rps_s)�->�bool fun{}�rps_win_s ��{r1:rps_s}�(x:�rps_t�(r1)): ��[r2:rps_s�│�rps_win_sta�(r2,�r1)]�(rps_t�(r2)) stacst�rps_win_sta:�(rps_s,�rps_s)�->�bool fun{}�rps_win_s ��{r1:rps_s}�(x:�rps_t�(r1)): ��[r2:rps_s�│�rps_win_sta�(r2,�r1)]�(rps_t�(r2))
  • 14.
    Implementation using Staticsof ATSImplementation using Statics of ATSImplementation using Statics of ATSImplementation using Statics of ATSImplementation using Statics of ATS extern�praxi�rps_win_r_s_pf�():�[rps_win_sta(r_rps_s,�s_rps_s)]�void�(*� Spec:�Paper�wins�Rock�*) extern�praxi�rps_win_p_r_pf�():�[rps_win_sta(p_rps_s,�r_rps_s)]�void�(*� Spec:�Scissors�win�Paper�*) extern�praxi�rps_win_s_p_pf�():�[rps_win_sta(s_rps_s,�p_rps_s)]�void�(*� Spec:�Rock�wins�Scissors�*) implement{}�rps_win_s�(x)�=�let ��prval�()�=�rps_win_r_s_pf()�(*�Introduce�specification�*) ��prval�()�=�rps_win_p_r_pf() ��prval�()�=�rps_win_s_p_pf() in ��case+�x�of ��│�r_rps_t()�=>�p_rps_t() ��│�p_rps_t()�=>�s_rps_t() ��│�s_rps_t()�=>�r_rps_t() end extern�praxi�rps_win_r_s_pf�():�[rps_win_sta(r_rps_s,�s_rps_s)]�void�(*� Spec:�Paper�wins�Rock�*) extern�praxi�rps_win_p_r_pf�():�[rps_win_sta(p_rps_s,�r_rps_s)]�void�(*� Spec:�Scissors�win�Paper�*) extern�praxi�rps_win_s_p_pf�():�[rps_win_sta(s_rps_s,�p_rps_s)]�void�(*� Spec:�Rock�wins�Scissors�*) implement{}�rps_win_s�(x)�=�let ��prval�()�=�rps_win_r_s_pf()�(*�Introduce�specification�*) ��prval�()�=�rps_win_p_r_pf() ��prval�()�=�rps_win_s_p_pf() in ��case+�x�of ��│�r_rps_t()�=>�p_rps_t() ��│�p_rps_t()�=>�s_rps_t() ��│�s_rps_t()�=>�r_rps_t() end extern�praxi�rps_win_r_s_pf�():�[rps_win_sta(r_rps_s,�s_rps_s)]�void�(*� Spec:�Paper�wins�Rock�*) extern�praxi�rps_win_p_r_pf�():�[rps_win_sta(p_rps_s,�r_rps_s)]�void�(*� Spec:�Scissors�win�Paper�*) extern�praxi�rps_win_s_p_pf�():�[rps_win_sta(s_rps_s,�p_rps_s)]�void�(*� Spec:�Rock�wins�Scissors�*) implement{}�rps_win_s�(x)�=�let ��prval�()�=�rps_win_r_s_pf()�(*�Introduce�specification�*) ��prval�()�=�rps_win_p_r_pf() ��prval�()�=�rps_win_s_p_pf() in ��case+�x�of ��│�r_rps_t()�=>�p_rps_t() ��│�p_rps_t()�=>�s_rps_t() ��│�s_rps_t()�=>�r_rps_t() end extern�praxi�rps_win_r_s_pf�():�[rps_win_sta(r_rps_s,�s_rps_s)]�void�(*� Spec:�Paper�wins�Rock�*) extern�praxi�rps_win_p_r_pf�():�[rps_win_sta(p_rps_s,�r_rps_s)]�void�(*� Spec:�Scissors�win�Paper�*) extern�praxi�rps_win_s_p_pf�():�[rps_win_sta(s_rps_s,�p_rps_s)]�void�(*� Spec:�Rock�wins�Scissors�*) implement{}�rps_win_s�(x)�=�let ��prval�()�=�rps_win_r_s_pf()�(*�Introduce�specification�*) ��prval�()�=�rps_win_p_r_pf() ��prval�()�=�rps_win_s_p_pf() in ��case+�x�of ��│�r_rps_t()�=>�p_rps_t() ��│�p_rps_t()�=>�s_rps_t() ��│�s_rps_t()�=>�r_rps_t() end extern praxi�rps_win_r_s_pf�():�[rps_win_sta(r_rps_s,�s_rps_s)]�void�(*� Spec:�Paper�wins�Rock�*) extern praxi�rps_win_p_r_pf�():�[rps_win_sta(p_rps_s,�r_rps_s)]�void�(*� Spec:�Scissors�win�Paper�*) extern praxi�rps_win_s_p_pf�():�[rps_win_sta(s_rps_s,�p_rps_s)]�void�(*� Spec:�Rock�wins�Scissors�*) implement{}�rps_win_s�(x)�=�let prval�()�=�rps_win_r_s_pf()�(*�Introduce�specification�*) prval�()�=�rps_win_p_r_pf() prval�()�=�rps_win_s_p_pf() in ��case+�x�of ��│�r_rps_t()�=>�p_rps_t() ��│�p_rps_t()�=>�s_rps_t() ��│�s_rps_t()�=>�r_rps_t() end
  • 15.
    Statics can catcherror at compile-timeStatics can catch error at compile-timeStatics can catch error at compile-timeStatics can catch error at compile-timeStatics can catch error at compile-time implement{}�rps_win_s�(x)�=�let ��prval�()�=�rps_win_r_s_pf()�(*�Introduce�specification�*) ��prval�()�=�rps_win_p_r_pf() ��prval�()�=�rps_win_s_p_pf() in ��case+�x�of ��│�r_rps_t()�=>�r_rps_t()�(*�Compile-time�error!�*) ��│�p_rps_t()�=>�s_rps_t() ��│�s_rps_t()�=>�r_rps_t() end implement{}�rps_win_s�(x)�=�let ��prval�()�=�rps_win_r_s_pf()�(*�Introduce�specification�*) ��prval�()�=�rps_win_p_r_pf() ��prval�()�=�rps_win_s_p_pf() in ��case+�x�of ��│�r_rps_t()�=>�r_rps_t()�(*�Compile-time�error!�*) ��│�p_rps_t()�=>�s_rps_t() ��│�s_rps_t()�=>�r_rps_t() end implement{}�rps_win_s�(x)�=�let ��prval�()�=�rps_win_r_s_pf()�(*�Introduce�specification�*) ��prval�()�=�rps_win_p_r_pf() ��prval�()�=�rps_win_s_p_pf() in ��case+�x�of ��│�r_rps_t()�=>�r_rps_t()�(*�Compile-time�error!�*) ��│�p_rps_t()�=>�s_rps_t() ��│�s_rps_t()�=>�r_rps_t() end implement{}�rps_win_s�(x)�=�let ��prval�()�=�rps_win_r_s_pf()�(*�Introduce�specification�*) ��prval�()�=�rps_win_p_r_pf() ��prval�()�=�rps_win_s_p_pf() in ��case+�x�of ��│�r_rps_t()�=>�r_rps_t()�(*�Compile-time�error!�*) ��│�p_rps_t()�=>�s_rps_t() ��│�s_rps_t()�=>�r_rps_t() end implement{}�rps_win_s�(x)�=�let prval�()�=�rps_win_r_s_pf()�(*�Introduce�specification�*) prval�()�=�rps_win_p_r_pf() prval�()�=�rps_win_s_p_pf() in ��case+�x�of ��│�r_rps_t()�=>�r_rps_t()�(*�Compile-time�error!�*) ��│�p_rps_t()�=>�s_rps_t() ��│�s_rps_t()�=>�r_rps_t() end $�patscc�main.dats�-DATS_MEMALLOC_LIBC /home/kiwamu/src/practice-ats/static_rps/rps.dats:�933(line=36,�offs=18)�--� 942(line=36,�offs=27):�error(3):�unsolved�constraint:�C3NSTRprop(C3TKmain();� S2Eapp(S2Ecst(rps_win_sta);�S2EVar(4434->S2Eapp(S2Ecst(r_rps_s);�)),�S2Evar (r1$2870(7929)))) $�patscc�main.dats�-DATS_MEMALLOC_LIBC /home/kiwamu/src/practice-ats/static_rps/rps.dats:�933(line=36,�offs=18)�--� 942(line=36,�offs=27):�error(3):�unsolved�constraint:�C3NSTRprop(C3TKmain();� S2Eapp(S2Ecst(rps_win_sta);�S2EVar(4434->S2Eapp(S2Ecst(r_rps_s);�)),�S2Evar (r1$2870(7929)))) $�patscc�main.dats�-DATS_MEMALLOC_LIBC /home/kiwamu/src/practice-ats/static_rps/rps.dats:�933(line=36,�offs=18)�--� 942(line=36,�offs=27):�error(3):�unsolved�constraint:�C3NSTRprop(C3TKmain();� S2Eapp(S2Ecst(rps_win_sta);�S2EVar(4434->S2Eapp(S2Ecst(r_rps_s);�)),�S2Evar (r1$2870(7929)))) $�patscc�main.dats�-DATS_MEMALLOC_LIBC /home/kiwamu/src/practice-ats/static_rps/rps.dats:�933(line=36,�offs=18)�--� 942(line=36,�offs=27):�error(3):�unsolved�constraint:�C3NSTRprop(C3TKmain();� S2Eapp(S2Ecst(rps_win_sta);�S2EVar(4434->S2Eapp(S2Ecst(r_rps_s);�)),�S2Evar (r1$2870(7929)))) $�patscc�main.dats�-DATS_MEMALLOC_LIBC /home/kiwamu/src/practice-ats/static_rps/rps.dats:�933(line=36,�offs=18)�--� 942(line=36,�offs=27):�error(3):�unsolved�constraint:�C3NSTRprop(C3TKmain();� S2Eapp(S2Ecst(rps_win_sta);�S2EVar(4434->S2Eapp(S2Ecst(r_rps_s);�)),�S2Evar (r1$2870(7929))))
  • 16.
    Specification using Proofsof ATSSpecification using Proofs of ATSSpecification using Proofs of ATSSpecification using Proofs of ATSSpecification using Proofs of ATS dataprop�RPS_WIN�(rps_s,�rps_s)�= ��│�RPS_P_WIN_R�(p_rps_s,�r_rps_s)�(*�Spec:�Paper�wins�Rock�*) ��│�RPS_S_WIN_P�(s_rps_s,�p_rps_s)�(*�Spec:�Scissors�win�Paper�*) ��│�RPS_R_WIN_S�(r_rps_s,�s_rps_s)�(*�Spec:�Rock�wins�Scissors�*) fun{}�rps_win_p ��{r1:rps_s}�(x:�rps_t�(r1)): ��[r2:rps_s]�(RPS_WIN�(r2,�r1)�│�rps_t�(r2)) dataprop�RPS_WIN�(rps_s,�rps_s)�= ��│�RPS_P_WIN_R�(p_rps_s,�r_rps_s)�(*�Spec:�Paper�wins�Rock�*) ��│�RPS_S_WIN_P�(s_rps_s,�p_rps_s)�(*�Spec:�Scissors�win�Paper�*) ��│�RPS_R_WIN_S�(r_rps_s,�s_rps_s)�(*�Spec:�Rock�wins�Scissors�*) fun{}�rps_win_p ��{r1:rps_s}�(x:�rps_t�(r1)): ��[r2:rps_s]�(RPS_WIN�(r2,�r1)�│�rps_t�(r2)) dataprop�RPS_WIN�(rps_s,�rps_s)�= ��│�RPS_P_WIN_R�(p_rps_s,�r_rps_s)�(*�Spec:�Paper�wins�Rock�*) ��│�RPS_S_WIN_P�(s_rps_s,�p_rps_s)�(*�Spec:�Scissors�win�Paper�*) ��│�RPS_R_WIN_S�(r_rps_s,�s_rps_s)�(*�Spec:�Rock�wins�Scissors�*) fun{}�rps_win_p ��{r1:rps_s}�(x:�rps_t�(r1)): ��[r2:rps_s]�(RPS_WIN�(r2,�r1)�│�rps_t�(r2)) dataprop�RPS_WIN�(rps_s,�rps_s)�= ��│�RPS_P_WIN_R�(p_rps_s,�r_rps_s)�(*�Spec:�Paper�wins�Rock�*) ��│�RPS_S_WIN_P�(s_rps_s,�p_rps_s)�(*�Spec:�Scissors�win�Paper�*) ��│�RPS_R_WIN_S�(r_rps_s,�s_rps_s)�(*�Spec:�Rock�wins�Scissors�*) fun{}�rps_win_p ��{r1:rps_s}�(x:�rps_t�(r1)): ��[r2:rps_s]�(RPS_WIN�(r2,�r1)�│�rps_t�(r2)) dataprop�RPS_WIN�(rps_s,�rps_s)�= ��│�RPS_P_WIN_R�(p_rps_s,�r_rps_s)�(*�Spec:�Paper�wins�Rock�*) ��│�RPS_S_WIN_P�(s_rps_s,�p_rps_s)�(*�Spec:�Scissors�win�Paper�*) ��│�RPS_R_WIN_S�(r_rps_s,�s_rps_s)�(*�Spec:�Rock�wins�Scissors�*) fun{}�rps_win_p ��{r1:rps_s}�(x:�rps_t�(r1)): ��[r2:rps_s]�(RPS_WIN�(r2,�r1)�│�rps_t�(r2))
  • 17.
    Implementation using Proofsof ATSImplementation using Proofs of ATSImplementation using Proofs of ATSImplementation using Proofs of ATSImplementation using Proofs of ATS implement{}�rps_win_p�(x)�=�case+�x�of ��│�r_rps_t()�=>�(RPS_P_WIN_R()�│�p_rps_t()) ��│�p_rps_t()�=>�(RPS_S_WIN_P()�│�s_rps_t()) ��│�s_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t()) implement{}�rps_win_p�(x)�=�case+�x�of ��│�r_rps_t()�=>�(RPS_P_WIN_R()�│�p_rps_t()) ��│�p_rps_t()�=>�(RPS_S_WIN_P()�│�s_rps_t()) ��│�s_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t()) implement{}�rps_win_p�(x)�=�case+�x�of ��│�r_rps_t()�=>�(RPS_P_WIN_R()�│�p_rps_t()) ��│�p_rps_t()�=>�(RPS_S_WIN_P()�│�s_rps_t()) ��│�s_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t()) implement{}�rps_win_p�(x)�=�case+�x�of ��│�r_rps_t()�=>�(RPS_P_WIN_R()�│�p_rps_t()) ��│�p_rps_t()�=>�(RPS_S_WIN_P()�│�s_rps_t()) ��│�s_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t()) implement{}�rps_win_p�(x)�=�case+�x�of ��│�r_rps_t()�=>�(RPS_P_WIN_R()�│�p_rps_t()) ��│�p_rps_t()�=>�(RPS_S_WIN_P()�│�s_rps_t()) ��│�s_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())
  • 18.
    Proofs can catcherror at compile-timeProofs can catch error at compile-timeProofs can catch error at compile-timeProofs can catch error at compile-timeProofs can catch error at compile-time implement{}�rps_win_p�(x)�=�case+�x�of ��│�r_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())�(*�Compile-time�error!�*) ��│�p_rps_t()�=>�(RPS_S_WIN_P()�│�s_rps_t()) ��│�s_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t()) implement{}�rps_win_p�(x)�=�case+�x�of ��│�r_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())�(*�Compile-time�error!�*) ��│�p_rps_t()�=>�(RPS_S_WIN_P()�│�s_rps_t()) ��│�s_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t()) implement{}�rps_win_p�(x)�=�case+�x�of ��│�r_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())�(*�Compile-time�error!�*) ��│�p_rps_t()�=>�(RPS_S_WIN_P()�│�s_rps_t()) ��│�s_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t()) implement{}�rps_win_p�(x)�=�case+�x�of ��│�r_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())�(*�Compile-time�error!�*) ��│�p_rps_t()�=>�(RPS_S_WIN_P()�│�s_rps_t()) ��│�s_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t()) implement{}�rps_win_p�(x)�=�case+�x�of ��│�r_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t())�(*�Compile-time�error!�*) ��│�p_rps_t()�=>�(RPS_S_WIN_P()�│�s_rps_t()) ��│�s_rps_t()�=>�(RPS_R_WIN_S()�│�r_rps_t()) $�patscc�main.dats�-DATS_MEMALLOC_LIBC /home/kiwamu/src/practice-ats/static_rps/rps.dats:�1199(line=45,�offs=18)�--� 1226(line=45,�offs=45):�error(3):�the�dynamic�expression�cannot�be�assigned� the�type�[S2Eexi(r2$2876(7935);�;�S2Etyrec(flt0;�npf=1;�0=S2Eapp(S2Ecst (RPS_WIN);�S2Evar(r2$2876(7935)),�S2Evar(r1$2875(7934))),�1=S2Eapp(S2Ecst (rps_t);�S2Evar(r2$2876(7935)))))]. $�patscc�main.dats�-DATS_MEMALLOC_LIBC /home/kiwamu/src/practice-ats/static_rps/rps.dats:�1199(line=45,�offs=18)�--� 1226(line=45,�offs=45):�error(3):�the�dynamic�expression�cannot�be�assigned� the�type�[S2Eexi(r2$2876(7935);�;�S2Etyrec(flt0;�npf=1;�0=S2Eapp(S2Ecst (RPS_WIN);�S2Evar(r2$2876(7935)),�S2Evar(r1$2875(7934))),�1=S2Eapp(S2Ecst (rps_t);�S2Evar(r2$2876(7935)))))]. $�patscc�main.dats�-DATS_MEMALLOC_LIBC /home/kiwamu/src/practice-ats/static_rps/rps.dats:�1199(line=45,�offs=18)�--� 1226(line=45,�offs=45):�error(3):�the�dynamic�expression�cannot�be�assigned� the�type�[S2Eexi(r2$2876(7935);�;�S2Etyrec(flt0;�npf=1;�0=S2Eapp(S2Ecst (RPS_WIN);�S2Evar(r2$2876(7935)),�S2Evar(r1$2875(7934))),�1=S2Eapp(S2Ecst (rps_t);�S2Evar(r2$2876(7935)))))]. $�patscc�main.dats�-DATS_MEMALLOC_LIBC /home/kiwamu/src/practice-ats/static_rps/rps.dats:�1199(line=45,�offs=18)�--� 1226(line=45,�offs=45):�error(3):�the�dynamic�expression�cannot�be�assigned� the�type�[S2Eexi(r2$2876(7935);�;�S2Etyrec(flt0;�npf=1;�0=S2Eapp(S2Ecst (RPS_WIN);�S2Evar(r2$2876(7935)),�S2Evar(r1$2875(7934))),�1=S2Eapp(S2Ecst (rps_t);�S2Evar(r2$2876(7935)))))]. $�patscc�main.dats�-DATS_MEMALLOC_LIBC /home/kiwamu/src/practice-ats/static_rps/rps.dats:�1199(line=45,�offs=18)�--� 1226(line=45,�offs=45):�error(3):�the�dynamic�expression�cannot�be�assigned� the�type�[S2Eexi(r2$2876(7935);�;�S2Etyrec(flt0;�npf=1;�0=S2Eapp(S2Ecst (RPS_WIN);�S2Evar(r2$2876(7935)),�S2Evar(r1$2875(7934))),�1=S2Eapp(S2Ecst (rps_t);�S2Evar(r2$2876(7935)))))].
  • 19.
    The code isfound at GitHubThe code is found at GitHubThe code is found at GitHubThe code is found at GitHubThe code is found at GitHub https://github.com/jats-ug/practice-ats/tree/master/static_rpshttps://github.com/jats-ug/practice-ats/tree/master/static_rpshttps://github.com/jats-ug/practice-ats/tree/master/static_rpshttps://github.com/jats-ug/practice-ats/tree/master/static_rpshttps://github.com/jats-ug/practice-ats/tree/master/static_rps
  • 20.
    License of photosLicenseof photosLicense of photosLicense of photosLicense of photos *�A�chart�showing�how�the�three�game�elements�of�"Rock-paper-scissors"� interact. ��https://en.wikipedia.org/wiki/Rock-paper-scissors#/media/File:Rock-paper- scissors.svg ��Copyright:�Antonsusi�/�License:�CC�BY-SA�3.0 *�Scissors�Rock�Paper�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/zombiesquirrels/3477986919/ ��Copyright:�Mike�Souza�/�License:�CC�BY-SA�2.0 *�AKB48�34th�Single�Selection�Rock,�Paper,�Scissors�Tournament:� Advertisement�at�Shibuya�Station�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/31029865@N06/15018892358/ ��Copyright:�Dick�Thomas�Johnson�/�License:�CC�BY�2.0 *�Cuddle�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/peptravassos/14206994372/ ��Copyright:�Pedro�Travassos�/�License:�CC�BY�2.0 *�Corey�Donohoe�(GitHub):�Metrics�Driven�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/stevelacey/5820920545/ ��Copyright:�Steve�Lacey�/�License:�CC�BY�2.0 *�Imagine�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/tonythemisfit/4773974792/ ��Copyright:�Tony�Fischer�/�License:�CC�BY�2.0 *�Creative�Commons�BBB�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/steren/2732488224/ ��Copyright:�Steren�Giannini�/�License:�CC�BY�2.0 *�A�chart�showing�how�the�three�game�elements�of�"Rock-paper-scissors"� interact. ��https://en.wikipedia.org/wiki/Rock-paper-scissors#/media/File:Rock-paper- scissors.svg ��Copyright:�Antonsusi�/�License:�CC�BY-SA�3.0 *�Scissors�Rock�Paper�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/zombiesquirrels/3477986919/ ��Copyright:�Mike�Souza�/�License:�CC�BY-SA�2.0 *�AKB48�34th�Single�Selection�Rock,�Paper,�Scissors�Tournament:� Advertisement�at�Shibuya�Station�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/31029865@N06/15018892358/ ��Copyright:�Dick�Thomas�Johnson�/�License:�CC�BY�2.0 *�Cuddle�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/peptravassos/14206994372/ ��Copyright:�Pedro�Travassos�/�License:�CC�BY�2.0 *�Corey�Donohoe�(GitHub):�Metrics�Driven�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/stevelacey/5820920545/ ��Copyright:�Steve�Lacey�/�License:�CC�BY�2.0 *�Imagine�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/tonythemisfit/4773974792/ ��Copyright:�Tony�Fischer�/�License:�CC�BY�2.0 *�Creative�Commons�BBB�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/steren/2732488224/ ��Copyright:�Steren�Giannini�/�License:�CC�BY�2.0 *�A�chart�showing�how�the�three�game�elements�of�"Rock-paper-scissors"� interact. ��https://en.wikipedia.org/wiki/Rock-paper-scissors#/media/File:Rock-paper- scissors.svg ��Copyright:�Antonsusi�/�License:�CC�BY-SA�3.0 *�Scissors�Rock�Paper�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/zombiesquirrels/3477986919/ ��Copyright:�Mike�Souza�/�License:�CC�BY-SA�2.0 *�AKB48�34th�Single�Selection�Rock,�Paper,�Scissors�Tournament:� Advertisement�at�Shibuya�Station�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/31029865@N06/15018892358/ ��Copyright:�Dick�Thomas�Johnson�/�License:�CC�BY�2.0 *�Cuddle�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/peptravassos/14206994372/ ��Copyright:�Pedro�Travassos�/�License:�CC�BY�2.0 *�Corey�Donohoe�(GitHub):�Metrics�Driven�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/stevelacey/5820920545/ ��Copyright:�Steve�Lacey�/�License:�CC�BY�2.0 *�Imagine�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/tonythemisfit/4773974792/ ��Copyright:�Tony�Fischer�/�License:�CC�BY�2.0 *�Creative�Commons�BBB�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/steren/2732488224/ ��Copyright:�Steren�Giannini�/�License:�CC�BY�2.0 *�A�chart�showing�how�the�three�game�elements�of�"Rock-paper-scissors"� interact. ��https://en.wikipedia.org/wiki/Rock-paper-scissors#/media/File:Rock-paper- scissors.svg ��Copyright:�Antonsusi�/�License:�CC�BY-SA�3.0 *�Scissors�Rock�Paper�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/zombiesquirrels/3477986919/ ��Copyright:�Mike�Souza�/�License:�CC�BY-SA�2.0 *�AKB48�34th�Single�Selection�Rock,�Paper,�Scissors�Tournament:� Advertisement�at�Shibuya�Station�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/31029865@N06/15018892358/ ��Copyright:�Dick�Thomas�Johnson�/�License:�CC�BY�2.0 *�Cuddle�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/peptravassos/14206994372/ ��Copyright:�Pedro�Travassos�/�License:�CC�BY�2.0 *�Corey�Donohoe�(GitHub):�Metrics�Driven�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/stevelacey/5820920545/ ��Copyright:�Steve�Lacey�/�License:�CC�BY�2.0 *�Imagine�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/tonythemisfit/4773974792/ ��Copyright:�Tony�Fischer�/�License:�CC�BY�2.0 *�Creative�Commons�BBB�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/steren/2732488224/ ��Copyright:�Steren�Giannini�/�License:�CC�BY�2.0 *�A�chart�showing�how�the�three�game�elements�of�"Rock-paper-scissors"� interact. ��https://en.wikipedia.org/wiki/Rock-paper-scissors#/media/File:Rock-paper- scissors.svg ��Copyright:�Antonsusi�/�License:�CC�BY-SA�3.0 *�Scissors�Rock�Paper�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/zombiesquirrels/3477986919/ ��Copyright:�Mike�Souza�/�License:�CC�BY-SA�2.0 *�AKB48�34th�Single�Selection�Rock,�Paper,�Scissors�Tournament:� Advertisement�at�Shibuya�Station�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/31029865@N06/15018892358/ ��Copyright:�Dick�Thomas�Johnson�/�License:�CC�BY�2.0 *�Cuddle�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/peptravassos/14206994372/ ��Copyright:�Pedro�Travassos�/�License:�CC�BY�2.0 *�Corey�Donohoe�(GitHub):�Metrics�Driven�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/stevelacey/5820920545/ ��Copyright:�Steve�Lacey�/�License:�CC�BY�2.0 *�Imagine�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/tonythemisfit/4773974792/ ��Copyright:�Tony�Fischer�/�License:�CC�BY�2.0 *�Creative�Commons�BBB�│�Flickr�-�Photo�Sharing! ��https://www.flickr.com/photos/steren/2732488224/ ��Copyright:�Steren�Giannini�/�License:�CC�BY�2.0