Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

ATS Programming Tutorial

11,949 views

Published on

ATS Programming Tutorial

Published in: Technology
  • Be the first to comment

ATS Programming Tutorial

  1. 1. ATS Programming TutorialATS Programming TutorialATS Programming TutorialATS Programming TutorialATS Programming Tutorial Kiwamu Okabe @ RIKEN AICSKiwamu Okabe @ RIKEN AICSKiwamu Okabe @ RIKEN AICSKiwamu Okabe @ RIKEN AICSKiwamu Okabe @ RIKEN AICS
  2. 2. Are you ready?Are you ready?Are you ready?Are you ready?Are you ready? Have you installed ATS2 compiler? If not, please install the ATS2 into your PC on following manual: Have you installed ATS2 compiler? If not, please install the ATS2 into your PC on following manual: Have you installed ATS2 compiler? If not, please install the ATS2 into your PC on following manual: Have you installed ATS2 compiler? If not, please install the ATS2 into your PC on following manual: Have you installed ATS2 compiler? If not, please install the ATS2 into your PC on following manual: ☆ In English: http://bit.ly/instats☆ In English: http://bit.ly/instats☆ In English: http://bit.ly/instats☆ In English: http://bit.ly/instats☆ In English: http://bit.ly/instats ☆ In Japanese: http://bit.ly/instatsj☆ In Japanese: http://bit.ly/instatsj☆ In Japanese: http://bit.ly/instatsj☆ In Japanese: http://bit.ly/instatsj☆ In Japanese: http://bit.ly/instatsj Also, you can get a code of this slide at following: Also, you can get a code of this slide at following: Also, you can get a code of this slide at following: Also, you can get a code of this slide at following: Also, you can get a code of this slide at following: ☆ http://bit.ly/ats20150306☆ http://bit.ly/ats20150306☆ http://bit.ly/ats20150306☆ http://bit.ly/ats20150306☆ http://bit.ly/ats20150306
  3. 3. Install ATS2 into Debian #1Install ATS2 into Debian #1Install ATS2 into Debian #1Install ATS2 into Debian #1Install ATS2 into Debian #1 ☆ Get source code of ATS2 compiler☆ Get source code of ATS2 compiler☆ Get source code of ATS2 compiler☆ Get source code of ATS2 compiler☆ Get source code of ATS2 compiler $ wget http://downloads.sourceforge.net/project/ats2-lang/ats2- lang/ats2-postiats-0.1.9/ATS2-Postiats-0.1.9.tgz $ wget http://downloads.sourceforge.net/project/ats2-lang-contrib/ ats2-lang-contrib/ATS2-Postiats-contrib-0.1.6.tgz $ wget http://downloads.sourceforge.net/project/ats2-lang/ats2- lang/ats2-postiats-0.1.9/ATS2-Postiats-0.1.9.tgz $ wget http://downloads.sourceforge.net/project/ats2-lang-contrib/ ats2-lang-contrib/ATS2-Postiats-contrib-0.1.6.tgz $ wget http://downloads.sourceforge.net/project/ats2-lang/ats2- lang/ats2-postiats-0.1.9/ATS2-Postiats-0.1.9.tgz $ wget http://downloads.sourceforge.net/project/ats2-lang-contrib/ ats2-lang-contrib/ATS2-Postiats-contrib-0.1.6.tgz $ wget http://downloads.sourceforge.net/project/ats2-lang/ats2- lang/ats2-postiats-0.1.9/ATS2-Postiats-0.1.9.tgz $ wget http://downloads.sourceforge.net/project/ats2-lang-contrib/ ats2-lang-contrib/ATS2-Postiats-contrib-0.1.6.tgz $ wget http://downloads.sourceforge.net/project/ats2-lang/ats2- lang/ats2-postiats-0.1.9/ATS2-Postiats-0.1.9.tgz $ wget http://downloads.sourceforge.net/project/ats2-lang-contrib/ ats2-lang-contrib/ATS2-Postiats-contrib-0.1.6.tgz ☆ Install packages needed by the ATS2☆ Install packages needed by the ATS2☆ Install packages needed by the ATS2☆ Install packages needed by the ATS2☆ Install packages needed by the ATS2 $ sudo apt-get install gcc libgc-dev libgmp-dev make$ sudo apt-get install gcc libgc-dev libgmp-dev make$ sudo apt-get install gcc libgc-dev libgmp-dev make$ sudo apt-get install gcc libgc-dev libgmp-dev make$ sudo apt-get install gcc libgc-dev libgmp-dev make
  4. 4. Install ATS2 into Debian #2Install ATS2 into Debian #2Install ATS2 into Debian #2Install ATS2 into Debian #2Install ATS2 into Debian #2 ☆ Compile the ATS2 compiler☆ Compile the ATS2 compiler☆ Compile the ATS2 compiler☆ Compile the ATS2 compiler☆ Compile the ATS2 compiler $ tar xf ATS2-Postiats-0.1.9.tgz $ export PATSHOME=`pwd`/ATS2-Postiats-0.1.9 $ export PATH=${PATSHOME}/bin:${PATH} $ tar xf ATS2-Postiats-contrib-0.1.6.tgz $ export PATSHOMERELOC=`pwd`/ATS2-Postiats-contrib-0.1.6 $ cd ${PATSHOME} $ ./configure $ make $ tar xf ATS2-Postiats-0.1.9.tgz $ export PATSHOME=`pwd`/ATS2-Postiats-0.1.9 $ export PATH=${PATSHOME}/bin:${PATH} $ tar xf ATS2-Postiats-contrib-0.1.6.tgz $ export PATSHOMERELOC=`pwd`/ATS2-Postiats-contrib-0.1.6 $ cd ${PATSHOME} $ ./configure $ make $ tar xf ATS2-Postiats-0.1.9.tgz $ export PATSHOME=`pwd`/ATS2-Postiats-0.1.9 $ export PATH=${PATSHOME}/bin:${PATH} $ tar xf ATS2-Postiats-contrib-0.1.6.tgz $ export PATSHOMERELOC=`pwd`/ATS2-Postiats-contrib-0.1.6 $ cd ${PATSHOME} $ ./configure $ make $ tar xf ATS2-Postiats-0.1.9.tgz $ export PATSHOME=`pwd`/ATS2-Postiats-0.1.9 $ export PATH=${PATSHOME}/bin:${PATH} $ tar xf ATS2-Postiats-contrib-0.1.6.tgz $ export PATSHOMERELOC=`pwd`/ATS2-Postiats-contrib-0.1.6 $ cd ${PATSHOME} $ ./configure $ make $ tar xf ATS2-Postiats-0.1.9.tgz $ export PATSHOME=`pwd`/ATS2-Postiats-0.1.9 $ export PATH=${PATSHOME}/bin:${PATH} $ tar xf ATS2-Postiats-contrib-0.1.6.tgz $ export PATSHOMERELOC=`pwd`/ATS2-Postiats-contrib-0.1.6 $ cd ${PATSHOME} $ ./configure $ make ☆ Ready to compile ATS code!☆ Ready to compile ATS code!☆ Ready to compile ATS code!☆ Ready to compile ATS code!☆ Ready to compile ATS code! $ patsopt --version ATS/Postiats version 0.1.9 with Copyright (c) 2011-2015 Hongwei Xi $ patsopt --version ATS/Postiats version 0.1.9 with Copyright (c) 2011-2015 Hongwei Xi $ patsopt --version ATS/Postiats version 0.1.9 with Copyright (c) 2011-2015 Hongwei Xi $ patsopt --version ATS/Postiats version 0.1.9 with Copyright (c) 2011-2015 Hongwei Xi $ patsopt --version ATS/Postiats version 0.1.9 with Copyright (c) 2011-2015 Hongwei Xi
  5. 5. What is ATS?What is ATS?What is ATS?What is ATS?What is ATS? http://www.ats-lang.org/http://www.ats-lang.org/http://www.ats-lang.org/http://www.ats-lang.org/http://www.ats-lang.org/ ☆ Syntax like ML☆ Syntax like ML☆ Syntax like ML☆ Syntax like ML☆ Syntax like ML ☆ Dependent types☆ Dependent types☆ Dependent types☆ Dependent types☆ Dependent types ☆ Linear types☆ Linear types☆ Linear types☆ Linear types☆ Linear types ☆ Optional GC☆ Optional GC☆ Optional GC☆ Optional GC☆ Optional GC ☆ Without any runtime☆ Without any runtime☆ Without any runtime☆ Without any runtime☆ Without any runtime ☆ Successor of Dependent ML☆ Successor of Dependent ML☆ Successor of Dependent ML☆ Successor of Dependent ML☆ Successor of Dependent ML
  6. 6. What can ATS do?What can ATS do?What can ATS do?What can ATS do?What can ATS do? ☆ Proof code using dependent types☆ Proof code using dependent types☆ Proof code using dependent types☆ Proof code using dependent types☆ Proof code using dependent types ☆ Safely use malloc using linear types☆ Safely use malloc using linear types☆ Safely use malloc using linear types☆ Safely use malloc using linear types☆ Safely use malloc using linear types ☆ Safely use pointer using linear types☆ Safely use pointer using linear types☆ Safely use pointer using linear types☆ Safely use pointer using linear types☆ Safely use pointer using linear types ☆ Use strong type without any OS☆ Use strong type without any OS☆ Use strong type without any OS☆ Use strong type without any OS☆ Use strong type without any OS ☆ Write code on bare metal hardware☆ Write code on bare metal hardware☆ Write code on bare metal hardware☆ Write code on bare metal hardware☆ Write code on bare metal hardware ☆ Write code in Linux kernel☆ Write code in Linux kernel☆ Write code in Linux kernel☆ Write code in Linux kernel☆ Write code in Linux kernel
  7. 7. The goal of todayThe goal of todayThe goal of todayThe goal of todayThe goal of today Already, ATS has some good documents.Already, ATS has some good documents.Already, ATS has some good documents.Already, ATS has some good documents.Already, ATS has some good documents. * Introduction to Programming in ATS http://ats-lang.sourceforge.net/DOCUMENT/INT2PROGINATS/HTML/ * A Tutorial on Programming Features in ATS http://ats-lang.sourceforge.net/DOCUMENT/ATS2TUTORIAL/HTML/ * Effective ATS http://ats-lang.sourceforge.net/EXAMPLE/EFFECTIVATS/ * Wiki for ATS2 https://github.com/githwxi/ATS-Postiats/wiki * Introduction to Programming in ATS http://ats-lang.sourceforge.net/DOCUMENT/INT2PROGINATS/HTML/ * A Tutorial on Programming Features in ATS http://ats-lang.sourceforge.net/DOCUMENT/ATS2TUTORIAL/HTML/ * Effective ATS http://ats-lang.sourceforge.net/EXAMPLE/EFFECTIVATS/ * Wiki for ATS2 https://github.com/githwxi/ATS-Postiats/wiki * Introduction to Programming in ATS http://ats-lang.sourceforge.net/DOCUMENT/INT2PROGINATS/HTML/ * A Tutorial on Programming Features in ATS http://ats-lang.sourceforge.net/DOCUMENT/ATS2TUTORIAL/HTML/ * Effective ATS http://ats-lang.sourceforge.net/EXAMPLE/EFFECTIVATS/ * Wiki for ATS2 https://github.com/githwxi/ATS-Postiats/wiki * Introduction to Programming in ATS http://ats-lang.sourceforge.net/DOCUMENT/INT2PROGINATS/HTML/ * A Tutorial on Programming Features in ATS http://ats-lang.sourceforge.net/DOCUMENT/ATS2TUTORIAL/HTML/ * Effective ATS http://ats-lang.sourceforge.net/EXAMPLE/EFFECTIVATS/ * Wiki for ATS2 https://github.com/githwxi/ATS-Postiats/wiki * Introduction to Programming in ATS http://ats-lang.sourceforge.net/DOCUMENT/INT2PROGINATS/HTML/ * A Tutorial on Programming Features in ATS http://ats-lang.sourceforge.net/DOCUMENT/ATS2TUTORIAL/HTML/ * Effective ATS http://ats-lang.sourceforge.net/EXAMPLE/EFFECTIVATS/ * Wiki for ATS2 https://github.com/githwxi/ATS-Postiats/wiki However, they are sometimes hard for beginner. The goal of today is to learn to read "Introduction to Programming in ATS" by yourself. However, they are sometimes hard for beginner. The goal of today is to learn to read "Introduction to Programming in ATS" by yourself. However, they are sometimes hard for beginner. The goal of today is to learn to read "Introduction to Programming in ATS" by yourself. However, they are sometimes hard for beginner. The goal of today is to learn to read "Introduction to Programming in ATS" by yourself. However, they are sometimes hard for beginner. The goal of today is to learn to read "Introduction to Programming in ATS" by yourself.
  8. 8. Hello WorldHello WorldHello WorldHello WorldHello World $ vi helloworld.dats val () = println! "Hello, world!" implement main0 () = () $ patscc helloworld.dats $ ./a.out Hello, world! $ vi helloworld.dats val () = println! "Hello, world!" implement main0 () = () $ patscc helloworld.dats $ ./a.out Hello, world! $ vi helloworld.dats val () = println! "Hello, world!" implement main0 () = () $ patscc helloworld.dats $ ./a.out Hello, world! $ vi helloworld.dats val () = println! "Hello, world!" implement main0 () = () $ patscc helloworld.dats $ ./a.out Hello, world! $ vi helloworld.dats val () = println! "Hello, world!" implement main0 () = () $ patscc helloworld.dats $ ./a.out Hello, world! You can call println! directly.You can call println! directly.You can call println! directly.You can call println! directly.You can call println! directly. $ vi helloworld2.dats implement main0 () = () where { val () = println! "Hello, world!" } $ vi helloworld2.dats implement main0 () = () where { val () = println! "Hello, world!" } $ vi helloworld2.dats implement main0 () = () where { val () = println! "Hello, world!" } $ vi helloworld2.dats implement main0 () = () where { val () = println! "Hello, world!" } $ vi helloworld2.dats implement main0 () = () where { val () = println! "Hello, world!" } Or more simply...Or more simply...Or more simply...Or more simply...Or more simply... $ vi helloworld3.dats implement main0 () = println! "Hello, world!" $ vi helloworld3.dats implement main0 () = println! "Hello, world!" $ vi helloworld3.dats implement main0 () = println! "Hello, world!" $ vi helloworld3.dats implement main0 () = println! "Hello, world!" $ vi helloworld3.dats implement main0 () = println! "Hello, world!"
  9. 9. IntegerIntegerIntegerIntegerInteger The "share/atspre_staload.hats" is needed by overloaded operators. The "share/atspre_staload.hats" is needed by overloaded operators. The "share/atspre_staload.hats" is needed by overloaded operators. The "share/atspre_staload.hats" is needed by overloaded operators. The "share/atspre_staload.hats" is needed by overloaded operators. $ vi int_op.dats #include "share/atspre_staload.hats" val () = println! (3 + 4 * 2) val () = println! ((3 + 4) * 2) val () = println! (2 - 3) val () = println! (7 / 2) val () = println! (7 % 2) implement main0 () = () $ patscc int_op.dats $ ./a.out 11 14 -1 3 1 $ vi int_op.dats #include "share/atspre_staload.hats" val () = println! (3 + 4 * 2) val () = println! ((3 + 4) * 2) val () = println! (2 - 3) val () = println! (7 / 2) val () = println! (7 % 2) implement main0 () = () $ patscc int_op.dats $ ./a.out 11 14 -1 3 1 $ vi int_op.dats #include "share/atspre_staload.hats" val () = println! (3 + 4 * 2) val () = println! ((3 + 4) * 2) val () = println! (2 - 3) val () = println! (7 / 2) val () = println! (7 % 2) implement main0 () = () $ patscc int_op.dats $ ./a.out 11 14 -1 3 1 $ vi int_op.dats #include "share/atspre_staload.hats" val () = println! (3 + 4 * 2) val () = println! ((3 + 4) * 2) val () = println! (2 - 3) val () = println! (7 / 2) val () = println! (7 % 2) implement main0 () = () $ patscc int_op.dats $ ./a.out 11 14 -1 3 1 $ vi int_op.dats #include "share/atspre_staload.hats" val () = println! (3 + 4 * 2) val () = println! ((3 + 4) * 2) val () = println! (2 - 3) val () = println! (7 / 2) val () = println! (7 % 2) implement main0 () = () $ patscc int_op.dats $ ./a.out 11 14 -1 3 1
  10. 10. Zero DivisionZero DivisionZero DivisionZero DivisionZero Division But, zero-division causes compile error!But, zero-division causes compile error!But, zero-division causes compile error!But, zero-division causes compile error!But, zero-division causes compile error! $ vi divmod.dats #include "share/atspre_staload.hats" val () = println! (7 / (2 - 2)) implement main0 () = () $ patscc divmod.dats /home/kiwamu/tmp/tmp/divmod.dats: 60(line=3, offs=22) -- 61 r ))) typechecking has failed: there are some unsolved constraints: please inspect the above reported error message(s) for information. exit(ATS): uncaught exception: _2home_2kiwamu_2src_2ATS_2dPostiats_2src_2pats_error_2esats__FatalE rrorExn(1025) $ vi divmod.dats #include "share/atspre_staload.hats" val () = println! (7 / (2 - 2)) implement main0 () = () $ patscc divmod.dats /home/kiwamu/tmp/tmp/divmod.dats: 60(line=3, offs=22) -- 61 r ))) typechecking has failed: there are some unsolved constraints: please inspect the above reported error message(s) for information. exit(ATS): uncaught exception: _2home_2kiwamu_2src_2ATS_2dPostiats_2src_2pats_error_2esats__FatalE rrorExn(1025) $ vi divmod.dats #include "share/atspre_staload.hats" val () = println! (7 / (2 - 2)) implement main0 () = () $ patscc divmod.dats /home/kiwamu/tmp/tmp/divmod.dats: 60(line=3, offs=22) -- 61 r ))) typechecking has failed: there are some unsolved constraints: please inspect the above reported error message(s) for information. exit(ATS): uncaught exception: _2home_2kiwamu_2src_2ATS_2dPostiats_2src_2pats_error_2esats__FatalE rrorExn(1025) $ vi divmod.dats #include "share/atspre_staload.hats" val () = println! (7 / (2 - 2)) implement main0 () = () $ patscc divmod.dats /home/kiwamu/tmp/tmp/divmod.dats: 60(line=3, offs=22) -- 61 r ))) typechecking has failed: there are some unsolved constraints: please inspect the above reported error message(s) for information. exit(ATS): uncaught exception: _2home_2kiwamu_2src_2ATS_2dPostiats_2src_2pats_error_2esats__FatalE rrorExn(1025) $ vi divmod.dats #include "share/atspre_staload.hats" val () = println! (7 / (2 - 2)) implement main0 () = () $ patscc divmod.dats /home/kiwamu/tmp/tmp/divmod.dats: 60(line=3, offs=22) -- 61 r ))) typechecking has failed: there are some unsolved constraints: please inspect the above reported error message(s) for information. exit(ATS): uncaught exception: _2home_2kiwamu_2src_2ATS_2dPostiats_2src_2pats_error_2esats__FatalE rrorExn(1025) The error message is hard to be read ...The error message is hard to be read ...The error message is hard to be read ...The error message is hard to be read ...The error message is hard to be read ...
  11. 11. Understanding internal typesUnderstanding internal typesUnderstanding internal typesUnderstanding internal typesUnderstanding internal types Let's decode the error message that is represented on following internal types: Let's decode the error message that is represented on following internal types: Let's decode the error message that is represented on following internal types: Let's decode the error message that is represented on following internal types: Let's decode the error message that is represented on following internal types: https://github.com/githwxi/ATS-Postiats/wiki/Internal-types * S2Eapp - an application term. * S2Ecst - a type constant (for instance, int, bool, list, etc.) * S2Eeff - function effects. * S2Eexi - an existentially quantified type. * S2Eint - machine precision integer. * S2Eintinf - infinite precision integer; commonly used for integer sorts in most compiled versions of atsopt (patsopt). * S2Evar - a (typically universally quantified) variable. * S2Etop (0; T) means T? * S2Etop (1; T) means T?! * S2EVar - an (existentially quantified) unification variable introduced by the typechecker. https://github.com/githwxi/ATS-Postiats/wiki/Internal-types * S2Eapp - an application term. * S2Ecst - a type constant (for instance, int, bool, list, etc.) * S2Eeff - function effects. * S2Eexi - an existentially quantified type. * S2Eint - machine precision integer. * S2Eintinf - infinite precision integer; commonly used for integer sorts in most compiled versions of atsopt (patsopt). * S2Evar - a (typically universally quantified) variable. * S2Etop (0; T) means T? * S2Etop (1; T) means T?! * S2EVar - an (existentially quantified) unification variable introduced by the typechecker. https://github.com/githwxi/ATS-Postiats/wiki/Internal-types * S2Eapp - an application term. * S2Ecst - a type constant (for instance, int, bool, list, etc.) * S2Eeff - function effects. * S2Eexi - an existentially quantified type. * S2Eint - machine precision integer. * S2Eintinf - infinite precision integer; commonly used for integer sorts in most compiled versions of atsopt (patsopt). * S2Evar - a (typically universally quantified) variable. * S2Etop (0; T) means T? * S2Etop (1; T) means T?! * S2EVar - an (existentially quantified) unification variable introduced by the typechecker. https://github.com/githwxi/ATS-Postiats/wiki/Internal-types * S2Eapp - an application term. * S2Ecst - a type constant (for instance, int, bool, list, etc.) * S2Eeff - function effects. * S2Eexi - an existentially quantified type. * S2Eint - machine precision integer. * S2Eintinf - infinite precision integer; commonly used for integer sorts in most compiled versions of atsopt (patsopt). * S2Evar - a (typically universally quantified) variable. * S2Etop (0; T) means T? * S2Etop (1; T) means T?! * S2EVar - an (existentially quantified) unification variable introduced by the typechecker. https://github.com/githwxi/ATS-Postiats/wiki/Internal-types * S2Eapp - an application term. * S2Ecst - a type constant (for instance, int, bool, list, etc.) * S2Eeff - function effects. * S2Eexi - an existentially quantified type. * S2Eint - machine precision integer. * S2Eintinf - infinite precision integer; commonly used for integer sorts in most compiled versions of atsopt (patsopt). * S2Evar - a (typically universally quantified) variable. * S2Etop (0; T) means T? * S2Etop (1; T) means T?! * S2EVar - an (existentially quantified) unification variable introduced by the typechecker.
  12. 12. The zero division error means...The zero division error means...The zero division error means...The zero division error means...The zero division error means... unsolved constraint: C3NSTRprop(main; S2Eapp(S2Ecst(!=); S2EVar (4177->S2Eapp(S2Ecst(sub_int_int); S2EVar(4173->S2Eintinf(2)), S2EVar(4174->S2Eintinf(2)))), S2Eintinf(0))) ↓ meaning The proposition "2 - 2 != 0" is not solved. unsolved constraint: C3NSTRprop(main; S2Eapp(S2Ecst(!=); S2EVar (4177->S2Eapp(S2Ecst(sub_int_int); S2EVar(4173->S2Eintinf(2)), S2EVar(4174->S2Eintinf(2)))), S2Eintinf(0))) ↓ meaning The proposition "2 - 2 != 0" is not solved. unsolved constraint: C3NSTRprop(main; S2Eapp(S2Ecst(!=); S2EVar (4177->S2Eapp(S2Ecst(sub_int_int); S2EVar(4173->S2Eintinf(2)), S2EVar(4174->S2Eintinf(2)))), S2Eintinf(0))) ↓ meaning The proposition "2 - 2 != 0" is not solved. unsolved constraint: C3NSTRprop(main; S2Eapp(S2Ecst(!=); S2EVar (4177->S2Eapp(S2Ecst(sub_int_int); S2EVar(4173->S2Eintinf(2)), S2EVar(4174->S2Eintinf(2)))), S2Eintinf(0))) ↓ meaning The proposition "2 - 2 != 0" is not solved. unsolved constraint: C3NSTRprop(main; S2Eapp(S2Ecst(!=); S2EVar (4177->S2Eapp(S2Ecst(sub_int_int); S2EVar(4173->S2Eintinf(2)), S2EVar(4174->S2Eintinf(2)))), S2Eintinf(0))) ↓ meaning The proposition "2 - 2 != 0" is not solved. It's powered by dependent types that are used at ATS language's prelude. It's powered by dependent types that are used at ATS language's prelude. It's powered by dependent types that are used at ATS language's prelude. It's powered by dependent types that are used at ATS language's prelude. It's powered by dependent types that are used at ATS language's prelude. $ vi ATS-Postiats/prelude/SATS/integer.sats typedef g1int_div_type (tk:tk) = {i,j:int | j != 0} (g1int (tk, i), g1int (tk, j)) -<fun0> g1int (tk) --snip-- fun g1int_div_int : g1int_div_type (intknd) = "mac#%" fun g1int_div_lint : g1int_div_type (lintknd) = "mac#%" fun g1int_div_llint : g1int_div_type (llintknd) = "mac#%" fun g1int_div_ssize : g1int_div_type (ssizeknd) = "mac#%" $ vi ATS-Postiats/prelude/SATS/integer.sats typedef g1int_div_type (tk:tk) = {i,j:int | j != 0} (g1int (tk, i), g1int (tk, j)) -<fun0> g1int (tk) --snip-- fun g1int_div_int : g1int_div_type (intknd) = "mac#%" fun g1int_div_lint : g1int_div_type (lintknd) = "mac#%" fun g1int_div_llint : g1int_div_type (llintknd) = "mac#%" fun g1int_div_ssize : g1int_div_type (ssizeknd) = "mac#%" $ vi ATS-Postiats/prelude/SATS/integer.sats typedef g1int_div_type (tk:tk) = {i,j:int | j != 0} (g1int (tk, i), g1int (tk, j)) -<fun0> g1int (tk) --snip-- fun g1int_div_int : g1int_div_type (intknd) = "mac#%" fun g1int_div_lint : g1int_div_type (lintknd) = "mac#%" fun g1int_div_llint : g1int_div_type (llintknd) = "mac#%" fun g1int_div_ssize : g1int_div_type (ssizeknd) = "mac#%" $ vi ATS-Postiats/prelude/SATS/integer.sats typedef g1int_div_type (tk:tk) = {i,j:int | j != 0} (g1int (tk, i), g1int (tk, j)) -<fun0> g1int (tk) --snip-- fun g1int_div_int : g1int_div_type (intknd) = "mac#%" fun g1int_div_lint : g1int_div_type (lintknd) = "mac#%" fun g1int_div_llint : g1int_div_type (llintknd) = "mac#%" fun g1int_div_ssize : g1int_div_type (ssizeknd) = "mac#%" $ vi ATS-Postiats/prelude/SATS/integer.sats typedef g1int_div_type (tk:tk) = {i,j:int | j != 0} (g1int (tk, i), g1int (tk, j)) -<fun0> g1int (tk) --snip-- fun g1int_div_int : g1int_div_type (intknd) = "mac#%" fun g1int_div_lint : g1int_div_type (lintknd) = "mac#%" fun g1int_div_llint : g1int_div_type (llintknd) = "mac#%" fun g1int_div_ssize : g1int_div_type (ssizeknd) = "mac#%"
  13. 13. Real NumberReal NumberReal NumberReal NumberReal Number $ vi double_op.dats #include "share/atspre_staload.hats" val () = println! ((3.0 + 5.0) * 8.0 / 3.0) implement main0 () = () $ patscc double_op.dats $ ./a.out 21.333333 $ vi double_op.dats #include "share/atspre_staload.hats" val () = println! ((3.0 + 5.0) * 8.0 / 3.0) implement main0 () = () $ patscc double_op.dats $ ./a.out 21.333333 $ vi double_op.dats #include "share/atspre_staload.hats" val () = println! ((3.0 + 5.0) * 8.0 / 3.0) implement main0 () = () $ patscc double_op.dats $ ./a.out 21.333333 $ vi double_op.dats #include "share/atspre_staload.hats" val () = println! ((3.0 + 5.0) * 8.0 / 3.0) implement main0 () = () $ patscc double_op.dats $ ./a.out 21.333333 $ vi double_op.dats #include "share/atspre_staload.hats" val () = println! ((3.0 + 5.0) * 8.0 / 3.0) implement main0 () = () $ patscc double_op.dats $ ./a.out 21.333333 The operators are overloaded.The operators are overloaded.The operators are overloaded.The operators are overloaded.The operators are overloaded. $ vi double_int_op.dats #include "share/atspre_staload.hats" val () = println! ((3 + 5.0) * 8 / 3.0) implement main0 () = () $ patscc double_int_op.dats $ ./a.out 21.333333 $ vi double_int_op.dats #include "share/atspre_staload.hats" val () = println! ((3 + 5.0) * 8 / 3.0) implement main0 () = () $ patscc double_int_op.dats $ ./a.out 21.333333 $ vi double_int_op.dats #include "share/atspre_staload.hats" val () = println! ((3 + 5.0) * 8 / 3.0) implement main0 () = () $ patscc double_int_op.dats $ ./a.out 21.333333 $ vi double_int_op.dats #include "share/atspre_staload.hats" val () = println! ((3 + 5.0) * 8 / 3.0) implement main0 () = () $ patscc double_int_op.dats $ ./a.out 21.333333 $ vi double_int_op.dats #include "share/atspre_staload.hats" val () = println! ((3 + 5.0) * 8 / 3.0) implement main0 () = () $ patscc double_int_op.dats $ ./a.out 21.333333
  14. 14. Boolean valueBoolean valueBoolean valueBoolean valueBoolean value $ vi bool_op.dats #include "share/atspre_staload.hats" val () = println! (true && false) val () = println! (not (false || not false && not false)) val () = println! (2 < 3) val () = println! (2 < 3 && 2.0 >= 3.0) val () = println! (2 < 3 || 2.0 = 3.0) val () = println! (not (3 < 2)) implement main0 () = () $ patscc bool_op.dats $ ./a.out false false true false true true $ vi bool_op.dats #include "share/atspre_staload.hats" val () = println! (true && false) val () = println! (not (false || not false && not false)) val () = println! (2 < 3) val () = println! (2 < 3 && 2.0 >= 3.0) val () = println! (2 < 3 || 2.0 = 3.0) val () = println! (not (3 < 2)) implement main0 () = () $ patscc bool_op.dats $ ./a.out false false true false true true $ vi bool_op.dats #include "share/atspre_staload.hats" val () = println! (true && false) val () = println! (not (false || not false && not false)) val () = println! (2 < 3) val () = println! (2 < 3 && 2.0 >= 3.0) val () = println! (2 < 3 || 2.0 = 3.0) val () = println! (not (3 < 2)) implement main0 () = () $ patscc bool_op.dats $ ./a.out false false true false true true $ vi bool_op.dats #include "share/atspre_staload.hats" val () = println! (true && false) val () = println! (not (false || not false && not false)) val () = println! (2 < 3) val () = println! (2 < 3 && 2.0 >= 3.0) val () = println! (2 < 3 || 2.0 = 3.0) val () = println! (not (3 < 2)) implement main0 () = () $ patscc bool_op.dats $ ./a.out false false true false true true $ vi bool_op.dats #include "share/atspre_staload.hats" val () = println! (true && false) val () = println! (not (false || not false && not false)) val () = println! (2 < 3) val () = println! (2 < 3 && 2.0 >= 3.0) val () = println! (2 < 3 || 2.0 = 3.0) val () = println! (not (3 < 2)) implement main0 () = () $ patscc bool_op.dats $ ./a.out false false true false true true
  15. 15. Constant definitionConstant definitionConstant definitionConstant definitionConstant definition $ vi val_overwrite.dats #include "share/atspre_staload.hats" implement main0 () = { val a = 1 val b = a val () = println! a val () = println! b val a = 2 val () = println! a val () = println! b } $ patscc val_overwrite.dats $ ./a.out 1 1 2 1 $ vi val_overwrite.dats #include "share/atspre_staload.hats" implement main0 () = { val a = 1 val b = a val () = println! a val () = println! b val a = 2 val () = println! a val () = println! b } $ patscc val_overwrite.dats $ ./a.out 1 1 2 1 $ vi val_overwrite.dats #include "share/atspre_staload.hats" implement main0 () = { val a = 1 val b = a val () = println! a val () = println! b val a = 2 val () = println! a val () = println! b } $ patscc val_overwrite.dats $ ./a.out 1 1 2 1 $ vi val_overwrite.dats #include "share/atspre_staload.hats" implement main0 () = { val a = 1 val b = a val () = println! a val () = println! b val a = 2 val () = println! a val () = println! b } $ patscc val_overwrite.dats $ ./a.out 1 1 2 1 $ vi val_overwrite.dats #include "share/atspre_staload.hats" implement main0 () = { val a = 1 val b = a val () = println! a val () = println! b val a = 2 val () = println! a val () = println! b } $ patscc val_overwrite.dats $ ./a.out 1 1 2 1
  16. 16. Function definitionFunction definitionFunction definitionFunction definitionFunction definition $ vi two_arguments.dats #include "share/atspre_staload.hats" fun g (x:int, y:int): int = x * x + y * y - 4 implement main0 () = println! (g (3, 2)) $ patscc two_arguments.dats $ ./a.out 9 $ vi two_arguments.dats #include "share/atspre_staload.hats" fun g (x:int, y:int): int = x * x + y * y - 4 implement main0 () = println! (g (3, 2)) $ patscc two_arguments.dats $ ./a.out 9 $ vi two_arguments.dats #include "share/atspre_staload.hats" fun g (x:int, y:int): int = x * x + y * y - 4 implement main0 () = println! (g (3, 2)) $ patscc two_arguments.dats $ ./a.out 9 $ vi two_arguments.dats #include "share/atspre_staload.hats" fun g (x:int, y:int): int = x * x + y * y - 4 implement main0 () = println! (g (3, 2)) $ patscc two_arguments.dats $ ./a.out 9 $ vi two_arguments.dats #include "share/atspre_staload.hats" fun g (x:int, y:int): int = x * x + y * y - 4 implement main0 () = println! (g (3, 2)) $ patscc two_arguments.dats $ ./a.out 9
  17. 17. TypecheckingTypecheckingTypecheckingTypecheckingTypechecking $ vi f_takes_double.dats #include "share/atspre_staload.hats" fun f (x:int): int = 3 * x implement main0 () = { val r = f 4.0 val () = println! r } $ patscc f_takes_double.dats /home/kiwamu/tmp/tmp/f_takes_double.dats: 103(line=6, offs=14) -- 106(line=6, offs=17): error(3): the dynamic expression cannot be /home/kiwamu/tmp/tmp/f_takes_double.dats: 103(line=6, offs=14) -- 106(line=6, offs=17): error(3): mismatch of static terms (tyleq): The actual term is: S2Eapp(S2Ecst(g0float_t0ype); S2Ecst (double_kind)) The needed term is: S2Eapp(S2Ecst(g0int_t0ype); S2Ecst(int_kind)) $ vi f_takes_double.dats #include "share/atspre_staload.hats" fun f (x:int): int = 3 * x implement main0 () = { val r = f 4.0 val () = println! r } $ patscc f_takes_double.dats /home/kiwamu/tmp/tmp/f_takes_double.dats: 103(line=6, offs=14) -- 106(line=6, offs=17): error(3): the dynamic expression cannot be /home/kiwamu/tmp/tmp/f_takes_double.dats: 103(line=6, offs=14) -- 106(line=6, offs=17): error(3): mismatch of static terms (tyleq): The actual term is: S2Eapp(S2Ecst(g0float_t0ype); S2Ecst (double_kind)) The needed term is: S2Eapp(S2Ecst(g0int_t0ype); S2Ecst(int_kind)) $ vi f_takes_double.dats #include "share/atspre_staload.hats" fun f (x:int): int = 3 * x implement main0 () = { val r = f 4.0 val () = println! r } $ patscc f_takes_double.dats /home/kiwamu/tmp/tmp/f_takes_double.dats: 103(line=6, offs=14) -- 106(line=6, offs=17): error(3): the dynamic expression cannot be /home/kiwamu/tmp/tmp/f_takes_double.dats: 103(line=6, offs=14) -- 106(line=6, offs=17): error(3): mismatch of static terms (tyleq): The actual term is: S2Eapp(S2Ecst(g0float_t0ype); S2Ecst (double_kind)) The needed term is: S2Eapp(S2Ecst(g0int_t0ype); S2Ecst(int_kind)) $ vi f_takes_double.dats #include "share/atspre_staload.hats" fun f (x:int): int = 3 * x implement main0 () = { val r = f 4.0 val () = println! r } $ patscc f_takes_double.dats /home/kiwamu/tmp/tmp/f_takes_double.dats: 103(line=6, offs=14) -- 106(line=6, offs=17): error(3): the dynamic expression cannot be /home/kiwamu/tmp/tmp/f_takes_double.dats: 103(line=6, offs=14) -- 106(line=6, offs=17): error(3): mismatch of static terms (tyleq): The actual term is: S2Eapp(S2Ecst(g0float_t0ype); S2Ecst (double_kind)) The needed term is: S2Eapp(S2Ecst(g0int_t0ype); S2Ecst(int_kind)) $ vi f_takes_double.dats #include "share/atspre_staload.hats" fun f (x:int): int = 3 * x implement main0 () = { val r = f 4.0 val () = println! r } $ patscc f_takes_double.dats /home/kiwamu/tmp/tmp/f_takes_double.dats: 103(line=6, offs=14) -- 106(line=6, offs=17): error(3): the dynamic expression cannot be /home/kiwamu/tmp/tmp/f_takes_double.dats: 103(line=6, offs=14) -- 106(line=6, offs=17): error(3): mismatch of static terms (tyleq): The actual term is: S2Eapp(S2Ecst(g0float_t0ype); S2Ecst (double_kind)) The needed term is: S2Eapp(S2Ecst(g0int_t0ype); S2Ecst(int_kind)) Function "f" should take value of int.Function "f" should take value of int.Function "f" should take value of int.Function "f" should take value of int.Function "f" should take value of int.
  18. 18. Conditional branchConditional branchConditional branchConditional branchConditional branch $ vi if_then_else.dats #include "share/atspre_staload.hats" implement main0 () = { val a = if 1 < 2 then 3 else 4 val () = println! (a:int) } $ patscc if_then_else.dats $ ./a.out 3 $ vi if_then_else.dats #include "share/atspre_staload.hats" implement main0 () = { val a = if 1 < 2 then 3 else 4 val () = println! (a:int) } $ patscc if_then_else.dats $ ./a.out 3 $ vi if_then_else.dats #include "share/atspre_staload.hats" implement main0 () = { val a = if 1 < 2 then 3 else 4 val () = println! (a:int) } $ patscc if_then_else.dats $ ./a.out 3 $ vi if_then_else.dats #include "share/atspre_staload.hats" implement main0 () = { val a = if 1 < 2 then 3 else 4 val () = println! (a:int) } $ patscc if_then_else.dats $ ./a.out 3 $ vi if_then_else.dats #include "share/atspre_staload.hats" implement main0 () = { val a = if 1 < 2 then 3 else 4 val () = println! (a:int) } $ patscc if_then_else.dats $ ./a.out 3
  19. 19. Able to drop else clauseAble to drop else clauseAble to drop else clauseAble to drop else clauseAble to drop else clause $ vi println_expr.dats #include "share/atspre_staload.hats" implement main0 () = if 7 > 5 then println! "It's true." $ patscc println_expr.dats $ ./a.out It's true. $ vi println_expr.dats #include "share/atspre_staload.hats" implement main0 () = if 7 > 5 then println! "It's true." $ patscc println_expr.dats $ ./a.out It's true. $ vi println_expr.dats #include "share/atspre_staload.hats" implement main0 () = if 7 > 5 then println! "It's true." $ patscc println_expr.dats $ ./a.out It's true. $ vi println_expr.dats #include "share/atspre_staload.hats" implement main0 () = if 7 > 5 then println! "It's true." $ patscc println_expr.dats $ ./a.out It's true. $ vi println_expr.dats #include "share/atspre_staload.hats" implement main0 () = if 7 > 5 then println! "It's true." $ patscc println_expr.dats $ ./a.out It's true.
  20. 20. Showing typesShowing typesShowing typesShowing typesShowing types $ vi showtype_int.dats val () = println! 3 val _ = $showtype 3 implement main0 () = () $ patscc showtype_int.dats **SHOWTYPE[UP]**(/home/kiwamu/tmp/tmp/showtype_int.dats: 39 (line=2, offs=19) -- 40(line=2, offs=20)): S2Eapp(S2Ecst (g1int_int_t0ype); S2Ecst(int_kind), S2Eintinf(3)): S2RTbas (S2RTBASimp(1; t@ype)) $ ./a.out 3 $ vi showtype_int.dats val () = println! 3 val _ = $showtype 3 implement main0 () = () $ patscc showtype_int.dats **SHOWTYPE[UP]**(/home/kiwamu/tmp/tmp/showtype_int.dats: 39 (line=2, offs=19) -- 40(line=2, offs=20)): S2Eapp(S2Ecst (g1int_int_t0ype); S2Ecst(int_kind), S2Eintinf(3)): S2RTbas (S2RTBASimp(1; t@ype)) $ ./a.out 3 $ vi showtype_int.dats val () = println! 3 val _ = $showtype 3 implement main0 () = () $ patscc showtype_int.dats **SHOWTYPE[UP]**(/home/kiwamu/tmp/tmp/showtype_int.dats: 39 (line=2, offs=19) -- 40(line=2, offs=20)): S2Eapp(S2Ecst (g1int_int_t0ype); S2Ecst(int_kind), S2Eintinf(3)): S2RTbas (S2RTBASimp(1; t@ype)) $ ./a.out 3 $ vi showtype_int.dats val () = println! 3 val _ = $showtype 3 implement main0 () = () $ patscc showtype_int.dats **SHOWTYPE[UP]**(/home/kiwamu/tmp/tmp/showtype_int.dats: 39 (line=2, offs=19) -- 40(line=2, offs=20)): S2Eapp(S2Ecst (g1int_int_t0ype); S2Ecst(int_kind), S2Eintinf(3)): S2RTbas (S2RTBASimp(1; t@ype)) $ ./a.out 3 $ vi showtype_int.dats val () = println! 3 val _ = $showtype 3 implement main0 () = () $ patscc showtype_int.dats **SHOWTYPE[UP]**(/home/kiwamu/tmp/tmp/showtype_int.dats: 39 (line=2, offs=19) -- 40(line=2, offs=20)): S2Eapp(S2Ecst (g1int_int_t0ype); S2Ecst(int_kind), S2Eintinf(3)): S2RTbas (S2RTBASimp(1; t@ype)) $ ./a.out 3 "Wiki for ATS2" explains "$showtype"."Wiki for ATS2" explains "$showtype"."Wiki for ATS2" explains "$showtype"."Wiki for ATS2" explains "$showtype"."Wiki for ATS2" explains "$showtype". "$showtype" prints out the type of a value or variable in ATS's internal type representation. Very helpful for understanding type errors, but the exact meaning of the output can still be cryptic for more complicated cases. "$showtype" prints out the type of a value or variable in ATS's internal type representation. Very helpful for understanding type errors, but the exact meaning of the output can still be cryptic for more complicated cases. "$showtype" prints out the type of a value or variable in ATS's internal type representation. Very helpful for understanding type errors, but the exact meaning of the output can still be cryptic for more complicated cases. "$showtype" prints out the type of a value or variable in ATS's internal type representation. Very helpful for understanding type errors, but the exact meaning of the output can still be cryptic for more complicated cases. "$showtype" prints out the type of a value or variable in ATS's internal type representation. Very helpful for understanding type errors, but the exact meaning of the output can still be cryptic for more complicated cases.
  21. 21. Immutable stringImmutable stringImmutable stringImmutable stringImmutable string $ vi print_foo.dats #include "share/atspre_staload.hats" val () = println! "foo" implement main0 () = () $ patscc print_foo.dats $ ./a.out foo $ vi print_foo.dats #include "share/atspre_staload.hats" val () = println! "foo" implement main0 () = () $ patscc print_foo.dats $ ./a.out foo $ vi print_foo.dats #include "share/atspre_staload.hats" val () = println! "foo" implement main0 () = () $ patscc print_foo.dats $ ./a.out foo $ vi print_foo.dats #include "share/atspre_staload.hats" val () = println! "foo" implement main0 () = () $ patscc print_foo.dats $ ./a.out foo $ vi print_foo.dats #include "share/atspre_staload.hats" val () = println! "foo" implement main0 () = () $ patscc print_foo.dats $ ./a.out foo However, immutable string can't do such like following: However, immutable string can't do such like following: However, immutable string can't do such like following: However, immutable string can't do such like following: However, immutable string can't do such like following: ☆ append☆ append☆ append☆ append☆ append ☆ reverse☆ reverse☆ reverse☆ reverse☆ reverse
  22. 22. Try to use mutable stringTry to use mutable stringTry to use mutable stringTry to use mutable stringTry to use mutable string $ vi try_string_append.dats #include "share/atspre_staload.hats" implement main0 () = { val s3 = string_append ("Yokohama", "Station") val () = println! s3 } $ patscc try_string_append.dats /home/kiwamu/tmp/try_string_append.dats: 60(line=3, offs=22) -- 135 (line=6, offs=2): error(3): the linear dynamic variable [s3$3509 (-1)] needs to be consumed but it is preserved with the type [S2Eapp(S2Ecst(strptr_addr_vtype); S2EVar(4175))] instead. patsopt(TRANS3): there are [1] errors in total. exit(ATS): uncaught exception: _2home_2kiwamu_2src_2ATS_2dPostiats_2src_2pats_error_2esats__FatalE rrorExn(1025) $ vi try_string_append.dats #include "share/atspre_staload.hats" implement main0 () = { val s3 = string_append ("Yokohama", "Station") val () = println! s3 } $ patscc try_string_append.dats /home/kiwamu/tmp/try_string_append.dats: 60(line=3, offs=22) -- 135 (line=6, offs=2): error(3): the linear dynamic variable [s3$3509 (-1)] needs to be consumed but it is preserved with the type [S2Eapp(S2Ecst(strptr_addr_vtype); S2EVar(4175))] instead. patsopt(TRANS3): there are [1] errors in total. exit(ATS): uncaught exception: _2home_2kiwamu_2src_2ATS_2dPostiats_2src_2pats_error_2esats__FatalE rrorExn(1025) $ vi try_string_append.dats #include "share/atspre_staload.hats" implement main0 () = { val s3 = string_append ("Yokohama", "Station") val () = println! s3 } $ patscc try_string_append.dats /home/kiwamu/tmp/try_string_append.dats: 60(line=3, offs=22) -- 135 (line=6, offs=2): error(3): the linear dynamic variable [s3$3509 (-1)] needs to be consumed but it is preserved with the type [S2Eapp(S2Ecst(strptr_addr_vtype); S2EVar(4175))] instead. patsopt(TRANS3): there are [1] errors in total. exit(ATS): uncaught exception: _2home_2kiwamu_2src_2ATS_2dPostiats_2src_2pats_error_2esats__FatalE rrorExn(1025) $ vi try_string_append.dats #include "share/atspre_staload.hats" implement main0 () = { val s3 = string_append ("Yokohama", "Station") val () = println! s3 } $ patscc try_string_append.dats /home/kiwamu/tmp/try_string_append.dats: 60(line=3, offs=22) -- 135 (line=6, offs=2): error(3): the linear dynamic variable [s3$3509 (-1)] needs to be consumed but it is preserved with the type [S2Eapp(S2Ecst(strptr_addr_vtype); S2EVar(4175))] instead. patsopt(TRANS3): there are [1] errors in total. exit(ATS): uncaught exception: _2home_2kiwamu_2src_2ATS_2dPostiats_2src_2pats_error_2esats__FatalE rrorExn(1025) $ vi try_string_append.dats #include "share/atspre_staload.hats" implement main0 () = { val s3 = string_append ("Yokohama", "Station") val () = println! s3 } $ patscc try_string_append.dats /home/kiwamu/tmp/try_string_append.dats: 60(line=3, offs=22) -- 135 (line=6, offs=2): error(3): the linear dynamic variable [s3$3509 (-1)] needs to be consumed but it is preserved with the type [S2Eapp(S2Ecst(strptr_addr_vtype); S2EVar(4175))] instead. patsopt(TRANS3): there are [1] errors in total. exit(ATS): uncaught exception: _2home_2kiwamu_2src_2ATS_2dPostiats_2src_2pats_error_2esats__FatalE rrorExn(1025) Why does error occur?Why does error occur?Why does error occur?Why does error occur?Why does error occur?
  23. 23. Need to free mutable stringNeed to free mutable stringNeed to free mutable stringNeed to free mutable stringNeed to free mutable string $ vi string_append.dats #include "share/atspre_staload.hats" implement main0 () = { val s3 = string_append ("Yokohama", "Station") val () = println! s3 val () = free s3 } $ patscc string_append.dats -DATS_MEMALLOC_LIBC $ ./a.out YokohamaStation $ vi string_append.dats #include "share/atspre_staload.hats" implement main0 () = { val s3 = string_append ("Yokohama", "Station") val () = println! s3 val () = free s3 } $ patscc string_append.dats -DATS_MEMALLOC_LIBC $ ./a.out YokohamaStation $ vi string_append.dats #include "share/atspre_staload.hats" implement main0 () = { val s3 = string_append ("Yokohama", "Station") val () = println! s3 val () = free s3 } $ patscc string_append.dats -DATS_MEMALLOC_LIBC $ ./a.out YokohamaStation $ vi string_append.dats #include "share/atspre_staload.hats" implement main0 () = { val s3 = string_append ("Yokohama", "Station") val () = println! s3 val () = free s3 } $ patscc string_append.dats -DATS_MEMALLOC_LIBC $ ./a.out YokohamaStation $ vi string_append.dats #include "share/atspre_staload.hats" implement main0 () = { val s3 = string_append ("Yokohama", "Station") val () = println! s3 val () = free s3 } $ patscc string_append.dats -DATS_MEMALLOC_LIBC $ ./a.out YokohamaStation The "ATS_MEMALLOC_LIBC" flag is needed to use malloc on libc. The "ATS_MEMALLOC_LIBC" flag is needed to use malloc on libc. The "ATS_MEMALLOC_LIBC" flag is needed to use malloc on libc. The "ATS_MEMALLOC_LIBC" flag is needed to use malloc on libc. The "ATS_MEMALLOC_LIBC" flag is needed to use malloc on libc. How can ATS2 know failure of free?How can ATS2 know failure of free?How can ATS2 know failure of free?How can ATS2 know failure of free?How can ATS2 know failure of free?
  24. 24. Linear type watches resourceLinear type watches resourceLinear type watches resourceLinear type watches resourceLinear type watches resource
  25. 25. Type of ListType of ListType of ListType of ListType of List
  26. 26. Create listCreate listCreate listCreate listCreate list $ vi make_pair.dats #include "share/atspre_staload.hats" implement main0 () = { val l = list_vt_make_pair (1, 2) val () = print_list_vt<int> l val () = list_vt_free<int> l } $ patscc make_pair.dats -DATS_MEMALLOC_LIBC $ ./a.out 1, 2 $ vi make_pair.dats #include "share/atspre_staload.hats" implement main0 () = { val l = list_vt_make_pair (1, 2) val () = print_list_vt<int> l val () = list_vt_free<int> l } $ patscc make_pair.dats -DATS_MEMALLOC_LIBC $ ./a.out 1, 2 $ vi make_pair.dats #include "share/atspre_staload.hats" implement main0 () = { val l = list_vt_make_pair (1, 2) val () = print_list_vt<int> l val () = list_vt_free<int> l } $ patscc make_pair.dats -DATS_MEMALLOC_LIBC $ ./a.out 1, 2 $ vi make_pair.dats #include "share/atspre_staload.hats" implement main0 () = { val l = list_vt_make_pair (1, 2) val () = print_list_vt<int> l val () = list_vt_free<int> l } $ patscc make_pair.dats -DATS_MEMALLOC_LIBC $ ./a.out 1, 2 $ vi make_pair.dats #include "share/atspre_staload.hats" implement main0 () = { val l = list_vt_make_pair (1, 2) val () = print_list_vt<int> l val () = list_vt_free<int> l } $ patscc make_pair.dats -DATS_MEMALLOC_LIBC $ ./a.out 1, 2 The "<int>" is needed to use template function. The "<int>" is needed to use template function. The "<int>" is needed to use template function. The "<int>" is needed to use template function. The "<int>" is needed to use template function.
  27. 27. Create list as figureCreate list as figureCreate list as figureCreate list as figureCreate list as figure
  28. 28. Append listAppend listAppend listAppend listAppend list $ vi append_list.dats #include "share/atspre_staload.hats" implement main0 () = { val l1 = list_vt_make_pair (1, 2) val l2 = list_vt_make_sing 3 val l3 = list_vt_append (l2, l1) val () = print_list_vt<int> l3 val () = list_vt_free<int> l3 } $ patscc append_list.dats -DATS_MEMALLOC_LIBC $ ./a.out 3, 1, 2 $ vi append_list.dats #include "share/atspre_staload.hats" implement main0 () = { val l1 = list_vt_make_pair (1, 2) val l2 = list_vt_make_sing 3 val l3 = list_vt_append (l2, l1) val () = print_list_vt<int> l3 val () = list_vt_free<int> l3 } $ patscc append_list.dats -DATS_MEMALLOC_LIBC $ ./a.out 3, 1, 2 $ vi append_list.dats #include "share/atspre_staload.hats" implement main0 () = { val l1 = list_vt_make_pair (1, 2) val l2 = list_vt_make_sing 3 val l3 = list_vt_append (l2, l1) val () = print_list_vt<int> l3 val () = list_vt_free<int> l3 } $ patscc append_list.dats -DATS_MEMALLOC_LIBC $ ./a.out 3, 1, 2 $ vi append_list.dats #include "share/atspre_staload.hats" implement main0 () = { val l1 = list_vt_make_pair (1, 2) val l2 = list_vt_make_sing 3 val l3 = list_vt_append (l2, l1) val () = print_list_vt<int> l3 val () = list_vt_free<int> l3 } $ patscc append_list.dats -DATS_MEMALLOC_LIBC $ ./a.out 3, 1, 2 $ vi append_list.dats #include "share/atspre_staload.hats" implement main0 () = { val l1 = list_vt_make_pair (1, 2) val l2 = list_vt_make_sing 3 val l3 = list_vt_append (l2, l1) val () = print_list_vt<int> l3 val () = list_vt_free<int> l3 } $ patscc append_list.dats -DATS_MEMALLOC_LIBC $ ./a.out 3, 1, 2
  29. 29. Append list as figureAppend list as figureAppend list as figureAppend list as figureAppend list as figure
  30. 30. Join "Japan ATS User Group" !Join "Japan ATS User Group" !Join "Japan ATS User Group" !Join "Japan ATS User Group" !Join "Japan ATS User Group" ! http://jats-ug.metasepi.org/http://jats-ug.metasepi.org/http://jats-ug.metasepi.org/http://jats-ug.metasepi.org/http://jats-ug.metasepi.org/ We translate following ATS documents into Japanese. We translate following ATS documents into Japanese. We translate following ATS documents into Japanese. We translate following ATS documents into Japanese. We translate following ATS documents into Japanese. * ATSプログラミング入門 http://jats-ug.metasepi.org/doc/ATS2/INT2PROGINATS/ * ATSプログラミングチュートリアル http://jats-ug.metasepi.org/doc/ATS2/ATS2TUTORIAL/ * Effective ATS https://github.com/jats-ug/translate/blob/master/Manual/ EffectiveATS.md * ATSプログラミング入門 http://jats-ug.metasepi.org/doc/ATS2/INT2PROGINATS/ * ATSプログラミングチュートリアル http://jats-ug.metasepi.org/doc/ATS2/ATS2TUTORIAL/ * Effective ATS https://github.com/jats-ug/translate/blob/master/Manual/ EffectiveATS.md * ATSプログラミング入門 http://jats-ug.metasepi.org/doc/ATS2/INT2PROGINATS/ * ATSプログラミングチュートリアル http://jats-ug.metasepi.org/doc/ATS2/ATS2TUTORIAL/ * Effective ATS https://github.com/jats-ug/translate/blob/master/Manual/ EffectiveATS.md * ATSプログラミング入門 http://jats-ug.metasepi.org/doc/ATS2/INT2PROGINATS/ * ATSプログラミングチュートリアル http://jats-ug.metasepi.org/doc/ATS2/ATS2TUTORIAL/ * Effective ATS https://github.com/jats-ug/translate/blob/master/Manual/ EffectiveATS.md * ATSプログラミング入門 http://jats-ug.metasepi.org/doc/ATS2/INT2PROGINATS/ * ATSプログラミングチュートリアル http://jats-ug.metasepi.org/doc/ATS2/ATS2TUTORIAL/ * Effective ATS https://github.com/jats-ug/translate/blob/master/Manual/ EffectiveATS.md Join us and review it!Join us and review it!Join us and review it!Join us and review it!Join us and review it!

×