<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Simple-typed Functional Language Modeled by Category Theory</article-title>
      </title-group>
      <contrib-group>
        <aff id="aff0">
          <label>0</label>
          <institution>Department of Computers and Informatics, Faculty of Electrical Engineering and Informatics, Technical University of Kosice</institution>
          ,
          <addr-line>Letna 9 042 00 Kosice</addr-line>
          ,
          <country>Slovak Republic</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>In this paper we present the simply-typed Lambda calculus extended by typed arithmetic expressions, Boolean values, derived forms, and reference types. We brie y present its syntax and semantics. Based on that we construct a model of this language using category theory.</p>
      </abstract>
      <kwd-group>
        <kwd>Category theory theory</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>
        The simply-typed Lambda calculus is considered to be the simplest functional
programming language. It was introduced by the Alonzo Church and Stephen
Kleen [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. In our work, we use a language extended by typed arithmetic
expressions, Boolean values, derived forms, and reference types. The goal of this
paper is to unify the individual extensions of simply-typed Lambda calculus to
one syntax, one many-typed signature, and one algebraic speci cation. Based on
that, we construct its corresponding model by category theory.
      </p>
      <p>
        In our previous research, we have worked with type theory and linear logic [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]
[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] where we have published our logical extensions of it. We have implemented
our extensions into teaching of type theory course in master level with interactive
web portal [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]. Our portal also include questionnaires for students. Based on that
we are trying to improve a course.
      </p>
      <p>
        -calculus and T-NBL De nition
-calculus with The typed Number Boolean Language (T-NBL) is the base
language of this paper. As the basic sets of typed expressions of the -calculus are
considered the sets of natural numbers Nat and boolean values Bool [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ], [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ].
      </p>
      <p>
        T ::= Bool j Nat
De nition of simple typed -calculus with functional-type and with typed
Number Boolean Language (T-NBL) is composed of semantics and syntax [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] with
the following syntax:
t ::= x j x : T:t j t t j (t)j true j false j if t then t else t j 0
j succ t j pred t j iszero t:
The rst four alternatives of the BNF production rule (2) belong to -calculus
and the others to T-NBL. Signature is de ne by applying the syntax of operations
and types. It is composed of pairs of sets [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ]:
{ T = fBool; Nat; T g represents a nite set of the names of basic types.
{ F = fx; abs; app; true; false; if; 0; succ; pred; iszerog represents a nite
set of the speci cation of operations.
      </p>
      <sec id="sec-1-1">
        <title>Signature has a pattern</title>
      </sec>
      <sec id="sec-1-2">
        <title>T NBL + k and the following form:</title>
        <p>= (T ; F )</p>
        <p>
          T NBL + k = (
T = fBool; N at; T g ;
FT NBL + K = f
true; f alse :! Bool;
0 :! N at;
succ : N at ! N at;
pred : N at ! N at;
iszero : N at ! Bool;
if : Bool; T; T ! T;
x :! T;
abs : T ! T;
app : (T ! T ); T ! T; g)
Model of algebraic speci cation is characterized by [
          <xref ref-type="bibr" rid="ref10">10</xref>
          ]:
1. Type assignment - to every type name T 2 T from signature
the appropriate type representation J T K,
2. Real operation assignment - to every speci cation of operation:
is assigned
(2)
(3)
(4)
(5)
(6)
is assigned a real appropriate operation:
        </p>
        <p>f : T1; : : : ; Tn ! T0
Jf K : JT1K
: : :</p>
        <p>JTnK ! J T0K:
Categorical model is created in the way that, to every name of basic types (Nat
or Bool) is assigned a set of real types (N or B) and also to the operation
speci cation, for example, to the pred is assigned a real operation JpredK. Real
operation works with semantic domens, on which is arity de ned by cartesian
product.</p>
        <p>Categorical model consists of objects and morphisms. Objects are considered
as semantical domens N, B, nal object 0, and the initial object f*g. Morphisms
are composed of operations as follows:</p>
        <p>Operation iszero is used for veri cation of zero value, is represented as</p>
        <sec id="sec-1-2-1">
          <title>Jsucc; predK : N ! N:</title>
        </sec>
        <sec id="sec-1-2-2">
          <title>JiszeroK : N ! B:</title>
          <p>The conditional operation if is represented as morphism</p>
        </sec>
        <sec id="sec-1-2-3">
          <title>JifK : B</title>
          <p>(B + N) (B + N) ! B + N:
{ the morphisms of the -calculus:
x : f*g ! B + N morphism for expression of variable.</p>
          <p>J K
JabsK : (B + N) ! (B + N) morphism for expression of abstraction.
JappK : (B + N)(B + N) (B + N) ! (B + N) morphism for expression
of application.</p>
          <p>Model contains coprojections 1, 2 and projections 1, 2, '1, '2, '3.</p>
          <p>The gure 1 shows categorical model of the T-NBL (purple color) with the
-calculus (orange color).
{ the morphisms of the T-NBL language:</p>
          <p>Jtrue=falseK : f*g ! B de nes the constants true or false.
0 : f*g ! N de nes the constant 0.</p>
          <p>J K
Operations successor and predecessor are represented in the model as
(7)
(8)
(9)
(10)
(11)
3</p>
        </sec>
      </sec>
    </sec>
    <sec id="sec-2">
      <title>Derived Forms De nition</title>
      <p>
        Some of the programming languages have side e ects, for that reason derived
forms are used [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ]. Derived forms ensures, that abbreviations are established to
-terms, determines the evaluation approach of -terms, simplifying the writing
and making the code more transparent. Every derived shape can be determined
with basic forms of -calculus, that are sequencing, wildcards, ascription and let
binding. We add a singleton set to basic sets of typed expressions on derived
forms [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ].
      </p>
      <p>{ T = fBool; Nat; Unit; T g,
{ F = fseq; wild; asc; letg.</p>
      <p>
        T ::= : : : j Unit
Syntax is extended by these alternatives [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ]:
t ::= : : : j ( x : Unit:t)t j (
: T:x)t j t as T j ( x : T:t);
where the rst alternative is sequence (seq), the second is wildcards (wild), the
third is ascription (asc) and the last one represents let binding (let).
      </p>
      <p>Signature of derived forms consists of following:</p>
      <p>Categorical model of derived forms consists of objects, with these semantic
domens N, B, U, nal object 0, and initial object f*g. Morphisms consists of
operations of derived forms as follows:
{ Operation sequence is represented as morphism JseqK : (U (B + N + U)) !</p>
      <p>B + N + U.
{ Wildcards are de ned as JwildK : B + N + U ! B + N + U.
{ Ascription represents morphism JascK : f g ! B + N + U,
{ Let binding is JletK : ((B + N + U) (B + N + U)) ! B + N + U.
Model contains coprojections 1, 2, 3 and projections 1, 2, '1, '2.</p>
      <p>
        Corresponding categorical model of derived forms is depicted in the gure 2.
In the previous sections we have mentioned just pure elements, but most
programming languages contains also inpure elements. That is the reason for some
of the side e ects, and for that referentions are used. Referention determines a
value, that contains an adress of another value. Reference types are types, that
use just as much memory, as much is needed for the calculation. The basic
operations of reference types are alloc, dereference and assign. We add a reference
type to the basic sets of typed expressions [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ], [13].
      </p>
      <p>
        Syntax is extended by these alternatives [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ]:
      </p>
      <p>T ::= : : : j Ref
t ::= : : : j ref t j !t j t := t;
(13)
where the rst alternative is alloc (ref), the second is dereference (!) and the last
one represents assign (:=).</p>
      <p>Signature of reference types consists of:
{ T = fBool; Nat; Unit; Ref; T g,
{ F = fref; !; :=g.</p>
      <sec id="sec-2-1">
        <title>And has a form:</title>
        <p>Ref = (
T = fBool; N at; U nit; T g ;
FREF = f
ref : T ! Ref T;
! : Ref T ! T;
:= : (Ref T T ) ! U nit; g)
(15)</p>
        <p>Categorical model of reference types is composed of objects [14], [15], where
belong these semantic domens N, B, R, U, nal object 0, and beginning object
f*g. Morphisms contains following operations:
{ alloc JrefK : (B + N + R + U) ! R (B + N + R + U),
{ dereference J!K : R (B + N + R + U) ! B + N + R + U,
{ assign J:=K : (B + N + R + U) (R (B + N + R + U)) ! U.
Model contains coprojections 1, 2, 3, 4 and projections 1, 2, '1, '2. The
corresponding categorical model of reference type is depicted in the gure 3.
In this paper, we introduce the simply typed -calculus extended by T-NBL,
derived forms and reference type.</p>
        <p>Basic sets of typed expressions are as follows:</p>
        <p>T ::= Bool j Natj Refj Unit:
The syntax of our language is expressed by the following BNF production rule:
t ::=
true j false j if t then t else t j 0 j succ t j pred t j iszero t j (t)
j x j x : T: t j t t j
j ref t j !t j t := t j
j ( x : Unit:t)t j ( : T:x)t j t as T j ( x : T:t):</p>
        <p>Signature of extended simply typed -calculus contains:
{ T = fBool; Nat; Unit; Ref; T g,
{ F = funion of sets FT NBL; F K; FREF a FDSg:</p>
        <p>Where:</p>
        <p>FT NBL = ftrue; false; 0; succ; pred; iszero; ifg,
F K = fx; abs; appg,
FREF = fref; !; :=g,</p>
        <p>FOT = fseq; wild; asc; letg.</p>
      </sec>
      <sec id="sec-2-2">
        <title>Signature has a form:</title>
        <p>+T NBL+OT +Ref = (
T = fBool; N at; U nit; T g ;
F = f
true; f alse :! Bool;
0 :! N at;
succ : N at ! N at;
pred : N at ! N at;
iszero : N at ! Bool;
if : Bool; T; T ! T;
x : ! T;
abs : T ! T;
app : (T ! T ); T ! T;
ref : T ! Ref T;
! : Re:f(RTef!TTT;) ! U nit;
:=
seq : U nit; T ! T;
wild : T ! T;
asc :! T;
let : T; T ! T g)
(16)
(17)
(18)</p>
        <p>The categorical model of typed -calculus extended by T-NBL, reference
and derived forms was created by merging of the categorical models from past
sections. It also contains following
{ coprojections 1, 2, 3, 4, and
{ projections 1, 2, 3, '1, '2, 1, 2, 1, 2, 1, 2, "1, "2.</p>
        <p>Categorical model is depicted in the next gure 4, where the separated extensions
are represented by di erent colors. Purple is for the extension of T-NBL, orange
stands for -calculus, green is for reference and blue represents the extension of
derived forms.</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>Conclusions</title>
      <p>In this paper, we have introduced the simply typed -calculus extended by
TNBL, derived forms, and reference types. The main result is a uni ed syntax,
signature, algebraic model, and categorical model of simply typed -calculus
extended by T-NBL, reference types, and derived forms. Final categorical model
contains all the extensions of the simply typed -calculus, they are separated by
di erent colors for better transparency of the model.</p>
    </sec>
    <sec id="sec-4">
      <title>Acknowledgment</title>
      <p>This work was supported by the following projects:
{ Faculty of Electrical Engineering and Informatics, Technical University of
Kosice under the contract No. FEI-2018-59: Semantic Machine of
SourceOriented Transparent Intensional Logic.
{ Slovak Research and Development Agency under the contract No.
SK-AT2017-0012: Semantics technologies for computer science education.
13. V. Novitzka and D. Mihalyi, \Polymorphic type theory as a base for categorical
logic," Acta Electrotechnica et Informatica No, vol. 7, no. 1, p. 3, 2007.
14. T. Hagino, \A typed lambda calculus with categorical type constructors," in
Category theory and computer science. Springer, 1987, pp. 140{157.
15. L. Vokorokos, A. Balaz, and M. Chovanec, \Distributed detection system of
security intrusions based on partially ordered events and patterns," in Towards
Intelligent Engineering and Information Technology. Springer, 2009, pp. 389{403.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>A.</given-names>
            <surname>Church</surname>
          </string-name>
          , \
          <article-title>A formulation of the simple theory of types,"</article-title>
          <source>The journal of symbolic logic</source>
          , vol.
          <volume>5</volume>
          , no.
          <issue>2</issue>
          , pp.
          <volume>56</volume>
          {
          <issue>68</issue>
          ,
          <year>1940</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>J.</given-names>
            <surname>Perhac</surname>
          </string-name>
          and
          <string-name>
            <given-names>D.</given-names>
            <surname>Mihalyi</surname>
          </string-name>
          , \
          <article-title>Intrusion detection system behavior as resourceoriented formula,"</article-title>
          <source>Acta Electrotechnica et Informatica</source>
          , vol.
          <volume>15</volume>
          , no.
          <issue>3</issue>
          , pp.
          <volume>9</volume>
          {
          <issue>13</issue>
          ,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>L.</given-names>
            <surname>Vokorokos</surname>
          </string-name>
          , E. Dankova, and
          <string-name>
            <given-names>N.</given-names>
            <surname>Adam</surname>
          </string-name>
          , \
          <article-title>Task scheduling in distributed system for photorealistic rendering,"</article-title>
          <source>in 2010 IEEE 8th International Symposium on Applied Machine Intelligence and Informatics (SAMI)</source>
          . IEEE,
          <year>2010</year>
          , pp.
          <volume>43</volume>
          {
          <fpage>47</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <given-names>J.</given-names>
            <surname>Juhar</surname>
          </string-name>
          and
          <string-name>
            <given-names>L.</given-names>
            <surname>Vokorokos</surname>
          </string-name>
          , \
          <article-title>Separation of concerns and concern granularity in source code,"</article-title>
          <source>in 2015 IEEE 13th International Scienti c Conference on Informatics. IEEE</source>
          ,
          <year>2015</year>
          , pp.
          <volume>139</volume>
          {
          <fpage>144</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <given-names>D.</given-names>
            <surname>Mihalyi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Peniaskova</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Perhac</surname>
          </string-name>
          , and
          <string-name>
            <given-names>J.</given-names>
            <surname>Mihelic</surname>
          </string-name>
          , \
          <article-title>Web based questionnaires for type theory course,"</article-title>
          <source>Acta Electrotechnica et Informatica</source>
          ,
          <year>2017</year>
          , (draft).
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <given-names>D.</given-names>
            <surname>Mihalyi</surname>
          </string-name>
          and
          <string-name>
            <given-names>V.</given-names>
            <surname>Novitzka</surname>
          </string-name>
          ,
          <article-title>Type theory</article-title>
          . Technical University of Kosice,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <given-names>V.</given-names>
            <surname>Novitzka</surname>
          </string-name>
          and
          <string-name>
            <given-names>A.</given-names>
            <surname>Verbova</surname>
          </string-name>
          , \
          <article-title>Dependent types in mathematical theory of programming."</article-title>
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <given-names>B. C.</given-names>
            <surname>Pierce</surname>
          </string-name>
          and
          <string-name>
            <given-names>C.</given-names>
            <surname>Benjamin</surname>
          </string-name>
          ,
          <article-title>Types and programming languages</article-title>
          . MIT press,
          <year>2002</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <given-names>H.</given-names>
            <surname>Reichel</surname>
          </string-name>
          ,
          <article-title>Initial computability, algebraic speci cations, and partial algebras</article-title>
          . Oxford University Press, Inc.,
          <year>1987</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <given-names>D.</given-names>
            <surname>Mihalyi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Lukac</surname>
          </string-name>
          , and
          <string-name>
            <given-names>V.</given-names>
            <surname>Novitzka</surname>
          </string-name>
          , \
          <article-title>Categorical semantics of reference data type,"</article-title>
          <source>Acta Electrotechnica et Informatica</source>
          , vol.
          <volume>13</volume>
          , no.
          <issue>4</issue>
          , pp.
          <volume>64</volume>
          {
          <issue>69</issue>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <surname>P. B. Andrews</surname>
          </string-name>
          ,
          <article-title>An introduction to mathematical logic and type theory</article-title>
          . Springer Science &amp; Business
          <string-name>
            <surname>Media</surname>
          </string-name>
          ,
          <year>2002</year>
          , vol.
          <volume>27</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          12. E. Chovancova,
          <string-name>
            <given-names>N.</given-names>
            <surname>Adam</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Balaz</surname>
          </string-name>
          , E. Pietrikova, P. Fecil'ak, S. Simonak, and
          <string-name>
            <given-names>M.</given-names>
            <surname>Chovanec</surname>
          </string-name>
          , \
          <article-title>Securing distributed computer systems using an advanced sophisticated hybrid honeypot technology,"</article-title>
          <source>Computing and Informatics</source>
          , vol.
          <volume>36</volume>
          , no.
          <issue>1</issue>
          , pp.
          <volume>113</volume>
          {
          <issue>139</issue>
          ,
          <year>2017</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>