39
Bibliography [AC96] Martin Abadi and Luca Cardelli. A Theory of Objects. Springer- Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF + 13] Esteban Allende, Oscar Calla´ u, Johan Fabry, ´ Eric Tanter, and Marcus Denker. Gradual typing for Smalltalk. Science of Com- puter Programming, August 2013. 2.3, 6.2 [ACPP89] Martin Abadi, Luca Cardelli, Benjamin Pierce, and Gordon Plotkin. Dynamic typing in a statically-typed language. In Proceedings of the 16th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’89, pages 213–227, New York, NY, USA, 1989. ACM. 2.1, 2.3 [AD03] Christopher Anderson and Sophia Drossopoulou. BabyJ: From object based to class based programming via types. Electronic Notes in Theoretical Computer Science, 82(8):53–81, 2003. 2.1, 2.4 [AFSW11] Amal Ahmed, Robert Bruce Findler, Jeremy G. Siek, and Philip Wadler. Blame for all. In Proceedings of the 38th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’11, pages 201–214, New York, NY, USA, 2011. ACM. 2.3 [AFT13] Esteban Allende, Johan Fabry, and ´ Eric Tanter. Cast insertion strategies for gradually-typed objects. In Proceedings of the 9th Symposium on Dynamic Languages, DLS ’13, pages 27–36, New York, NY, USA, 2013. ACM. 2.3, 3, 6.2 [BAT14] Gavin Bierman, Mart´ ın Abadi, and Mads Torgersen. Understand- ing TypeScript. In ECOOP 2014–Object-Oriented Programming, pages 257–281. Springer, 2014. 6.2 [BBH + 13] Andrew P. Black, Kim B. Bruce, Michael Homer, James Noble, Amy Ruskin, and Richard Yannow. Seeking Grace: A new object- oriented language for novices. In Proceedings of the 44th ACM

 · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Bibliography

[AC96] Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-

Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2

[ACF+13] Esteban Allende, Oscar Callau, Johan Fabry, Eric Tanter, and

Marcus Denker. Gradual typing for Smalltalk. Science of Com-

puter Programming, August 2013. 2.3, 6.2

[ACPP89] Martin Abadi, Luca Cardelli, Benjamin Pierce, and Gordon

Plotkin. Dynamic typing in a statically-typed language. In

Proceedings of the 16th ACM SIGPLAN-SIGACT Symposium on

Principles of Programming Languages, POPL ’89, pages 213–227,

New York, NY, USA, 1989. ACM. 2.1, 2.3

[AD03] Christopher Anderson and Sophia Drossopoulou. BabyJ: From

object based to class based programming via types. Electronic

Notes in Theoretical Computer Science, 82(8):53–81, 2003. 2.1,

2.4

[AFSW11] Amal Ahmed, Robert Bruce Findler, Jeremy G. Siek, and Philip

Wadler. Blame for all. In Proceedings of the 38th Annual ACM

SIGPLAN-SIGACT Symposium on Principles of Programming

Languages, POPL ’11, pages 201–214, New York, NY, USA, 2011.

ACM. 2.3

[AFT13] Esteban Allende, Johan Fabry, and Eric Tanter. Cast insertion

strategies for gradually-typed objects. In Proceedings of the 9th

Symposium on Dynamic Languages, DLS ’13, pages 27–36, New

York, NY, USA, 2013. ACM. 2.3, 3, 6.2

[BAT14] Gavin Bierman, Martın Abadi, and Mads Torgersen. Understand-

ing TypeScript. In ECOOP 2014–Object-Oriented Programming,

pages 257–281. Springer, 2014. 6.2

[BBH+13] Andrew P. Black, Kim B. Bruce, Michael Homer, James Noble,

Amy Ruskin, and Richard Yannow. Seeking Grace: A new object-

oriented language for novices. In Proceedings of the 44th ACM

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 2:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Bibliography 112

Technical Symposium on Computer Science Education, SIGCSE

’13, pages 129–134, New York, NY, USA, 2013. ACM. 2.3, 6.2

[BBHN12] Andrew P. Black, Kim B. Bruce, Michael Homer, and James

Noble. Grace: The absence of (inessential) difficulty. In Proceed-

ings of the ACM International Symposium on New Ideas, New

Paradigms, and Reflections on Programming and Software, On-

ward! ’12, pages 85–98, New York, NY, USA, 2012. ACM. 2.3

[BG93] Gilad Bracha and David Griswold. Strongtalk: Typechecking

Smalltalk in a production environment. In Proceedings of the

Eighth Annual Conference on Object-Oriented Programming Sys-

tems, Languages, and Applications, OOPSLA ’93, pages 215–230,

New York, NY, USA, 1993. ACM. 2.2

[Bra96] Gilad Bracha. The Strongtalk type system for Smalltalk. In Pro-

ceedings of the Workshop on Extending the Smalltalk Language,

OOPSLA, 1996. 2.2

[Bra04] Gilad Bracha. Pluggable type systems. In Proceedings of the

Workshop on Revival of Dynamic Languages, OOPSLA, October

2004. 1, 2.2

[BS12] Ambrose Bonnaire-Sergeant. A practical optional type system for

Clojure. Master’s thesis, University of Western Australia, 2012.

2.4, 6.2

[Car84] Luca Cardelli. A semantics of multiple inheritance. In Proceedings

of the International Symposium on Semantics of Data Types,

pages 51–67, New York, NY, USA, 1984. Springer-Verlag New

York, Inc. 4.2

[Car86] Luca Cardelli. Amber. In Proceedings of the Thirteenth Spring

School of the LITP on Combinators and Functional Programming

Languages, pages 21–47, London, UK, UK, 1986. Springer-Verlag.

4.2

[CF91] Robert Cartwright and Mike Fagan. Soft typing. In Proceedings of

the ACM SIGPLAN 1991 Conference on Programming Language

Design and Implementation, PLDI ’91, pages 278–292, New York,

NY, USA, 1991. ACM. 2.1

[Cha14] Pierre Chapuis. Lua HTTP Digest. https://github.com/

catwell/lua-http-digest, 2014. [Accessed February 2015]. 5

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 3:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Bibliography 113

[Cla14] Kevin Clancy. Lua Analyzer. https://bitbucket.org/

kevinclancy/lua-analyzer/, 2014. [Accessed February 2015].

6.1

[Cor11] Leaf Corcoran. MoonScript: A programmer friendly language

that compiles to Lua. http://moonscript.org/, 2011. [Accessed

February 2015]. 6.1

[dF14] Luiz Henrique de Figueiredo. lmd5 – A message digest library

for Lua based on OpenSSL. http://www.tecgraf.puc-rio.br/

~lhf/ftp/lua/, 2014. [Accessed Februrary 2015]. 3.8, 5

[Ern13] Emil Ernerfeldt. Sol. https://github.com/emilk/sol, 2013.

[Accessed Februrary 2015]. 6.1

[Fac14] Facebook. Hack. http://hacklang.org/, 2014. [Accessed

Februrary 2015]. 6.2

[FF02] Robert Bruce Findler and Matthias Felleisen. Contracts for

higher-order functions. In Proceedings of the 7th ACM SIGPLAN

International Conference on Functional Programming, ICFP ’02,

pages 48–59, New York, NY, USA, 2002. ACM. 2.1, 2.3

[Fla06] Cormac Flanagan. Hybrid type checking. In Conference Record

of the 33rd ACM SIGPLAN-SIGACT Symposium on Principles

of Programming Languages, POPL ’06, pages 245–256, New York,

NY, USA, 2006. ACM. 2.4, 5.3

[Fle07] Fabien Fleutot. Metalua: Static meta-programming for Lua.

https://github.com/fab13n/metalua, 2007. [Accessed Febru-

ary 2015]. 6.1

[Fle13] Fabien Fleutot. Tidal Lock: Gradual static typing for

Lua. https://github.com/fab13n/metalua/tree/tilo/src/

tilo, 2013. [Accessed Februrary 2015]. 6.1

[FT07] Fabien Fleutot and Laurence Tratt. Contrasting compile-time

meta-programming in Metalua and Converge. In Proceedings of

the Workshop on Dynamic Languages and Applications, 2007. 6.1

[GKT+06] Jessica Gronski, Kenneth Knowles, Aaron Tomb, Stephen N.

Freund, and Cormac Flanagan. Sage: Hybrid checking for flexible

specifications. In Scheme and Functional Programming Workshop,

pages 93–104, September 2006. 2.4

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 4:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Bibliography 114

[Goo11] Google. Dart. https://www.dartlang.org/, 2011. [Accessed

February 2015]. 2.2, 3, 6.2

[GSK11] Arjun Guha, Claudiu Saftoiu, and Shriram Krishnamurthi. Typ-

ing local control and state using flow analysis. In Proceedings

of the 20th European Conference on Programming Languages and

Systems: Part of the Joint European Conferences on Theory and

Practice of Software, ESOP’11/ETAPS’11, pages 256–275, Berlin,

Heidelberg, 2011. Springer-Verlag. 3.3, 6.2

[HBNB13] Michael Homer, Kim B. Bruce, James Noble, and Andrew P.

Black. Modules as gradually-typed objects. In Proceedings of the

7th Workshop on Dynamic Languages and Applications, DYLA

’13, pages 1:1–1:8, New York, NY, USA, 2013. ACM. 2.3, 6.2

[Hen94] Fritz Henglein. Dynamic typing: Syntax and proof theory. Science

of Computer Programming, 22(3):197–230, June 1994. 2.1, 2.3

[Hoe12] Rob Hoelz. Typical. https://github.com/hoelzro/

lua-typical, 2012. [Accessed February 2015]. 5

[HTF07] David Herman, Aaron Tomb, and Cormac Flanagan. Space-

efficient gradual typing. In Trends in Functional Programming,

pages 1–18, 2007. 2.3

[IdFC11] Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Walde-

mar Celes. Lua 5.2 Reference Manual. http://www.lua.org/

manual/5.2/manual.html, 2011. [Accessed February 2015]. 5,

5.1

[Ier08] Roberto Ierusalimschy. LPeg - parsing expression grammars for

Lua. http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html,

2008. [Accessed February 2015]. 5.8

[Ier09] Roberto Ierusalimschy. A text pattern-matching tool based on

parsing expression grammars. Software: Practice & Experience,

39(3):221–258, March 2009. 5.8

[JS11] R. James and A. Sabry. Yield: Mainstream delimited continu-

ations. In First International Workshop on the Theory and Prac-

tice of Delimited Continuations (TPDC 2011), page 20, 2011. 5.1

[Kep04] Kepler Project. LuaFileSystem. http://keplerproject.

github.io/luafilesystem/, 2004. [Accessed February 2015]. 5

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 5:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Bibliography 115

[Leh14a] Jukka Lehtosalo. mypy: Optional static typing for Python. http:

//www.mypy-lang.org/, 2014. [Accessed February 2015]. 6.2

[Leh14b] Jukka Lehtosalo. typing: Annotate your Python code. https:

//github.com/JukkaL/typing, 2014. [Accessed Februrary 2015].

6.2

[LG11] Jukka Lehtosalo and David J. Greaves. Language with a pluggable

type system and optional runtime monitoring of type errors.

In International Workshop on Scripts to Programs, STOP ’11,

January 2011. 2.4

[LPGK13] Benjamin S. Lerner, Joe Gibbs Politz, Arjun Guha, and Shriram

Krishnamurthi. TeJaS: Retrofitting type systems for JavaScript.

In Proceedings of the 9th Symposium on Dynamic Languages, DLS

’13, pages 1–16, New York, NY, USA, 2013. ACM. 6.2

[Maj15] Dibyendu Majumdar. Ravi. https://github.com/

dibyendumajumdar/ravi, 2015. [Accessed Februrary 2015].

6.1

[Man11] David Manura. LuaInspect. https://github.com/davidm/

lua-inspect, 2011. [Accessed February 2015]. 6.1

[Mel14] Peter Melnichenko. Luacheck. https://github.com/mpeterv/

luacheck, 2014. [Accessed February 2015]. 6.1

[MI09] Ana Lucia De Moura and Roberto Ierusalimschy. Revisiting

coroutines. ACM Transactions on Programming Languages and

Systems (TOPLAS), 31(2):6:1–6:31, February 2009. 5.1

[Mic12] Microsoft. TypeScript. http://www.typescriptlang.org/,

2012. [Accessed Februrary 2015]. 2.2, 3, 6.2

[MMI13] Hisham Muhammad, Fabio Mascarenhas, and Roberto Ierusalim-

schy. LuaRocks: a declarative and extensible package management

system for Lua. In Brazilian Symposium on Programming Lan-

guages, pages 16–30. Springer, 2013. 2.5

[Moo07] Colin Moock. Essential ActionScript 3.0. O’Reilly, 2007. 2.3

[Neh07] Diego Nehab. LuaSocket. http://w3.impa.br/~diego/

software/luasocket/, 2007. [Accessed February 2015]. 5

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 6:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Bibliography 116

[Neh08] Diego Nehab. Filters, sources, sinks, and pumps or functional

programming for the rest of us. In Luiz Henrique de Figueiredo,

Waldemar Celes, and Roberto Ierusalimschy, editors, Lua Pro-

gramming Gems. Lua.org, Rio de Janeiro, 2008. 5.3

[NN99] Flemming Nielson and Hanne Riis Nielson. Type and effect

systems. In Correct System Design, pages 114–136. Springer, 1999.

5.1

[OTMW04] Xinming Ou, Gang Tan, Yitzhak Mandelbaum, and David

Walker. Dynamic typing with dependent types. Exploring new

frontiers of theoretical informatics, pages 437–450, 2004. 2.1

[Pea13] David J. Pearce. A calculus for constraint-based flow typing. In

Proceedings of the 15th Workshop on Formal Techniques for Java-

like Programs, FTfJP ’13, pages 7:1–7:7, New York, NY, USA,

2013. ACM. 6.2

[PGK12] Joe Gibbs Politz, Arjun Guha, and Shriram Krishnamurthi. Se-

mantics and types for objects with first-class member names.

In FOOL 2012: 19th International Workshop on Foundations of

Object-Oriented Languages, page 37, 2012. 6.2

[Pie02] Benjamin C. Pierce. Types and Programming Languages. MIT

Press, Cambridge, MA, USA, 2002. 1

[PT00] Benjamin C. Pierce and David N. Turner. Local type inference.

ACM Transactions on Programming Languages and Systems (TO-

PLAS), 22(1):1–44, January 2000. 1, 3

[RTSF13] Brianna M. Ren, John Toman, T. Stephen Strickland, and Jef-

frey S. Foster. The Ruby Type Checker. In Object-Oriented

Program Languages and Systems (OOPS) Track at ACM Sym-

posium on Applied Computing, pages 1565–1572, Coimbra, Por-

tugal, March 2013. 6.2

[Sch14] Thijs Schreijer. Lua modulo11 number generator and verificator.

https://github.com/Tieske/mod11, 2014. [Accessed February

2015]. 5

[SGT09] Jeremy G. Siek, Ronald Garcia, and Walid Taha. Exploring the

design space of higher-order casts. In Proceedings of the 18th

European Symposium on Programming Languages and Systems:

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 7:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Bibliography 117

Held As Part of the Joint European Conferences on Theory and

Practice of Software, ETAPS 2009, ESOP ’09, pages 17–31, Ber-

lin, Heidelberg, 2009. Springer-Verlag. 2.3

[ST06] Jeremy G. Siek and Walid Taha. Gradual typing for functional

languages. In Scheme and Functional Programming Workshop,

pages 81–92, September 2006. 1, 2.2, 2.3, 2.3, 2.3, 2.3

[ST07] Jeremy G. Siek and Walid Taha. Gradual typing for objects. In

Proceedings of the 21st European Conference on Object-Oriented

Programming, ECOOP’07, pages 2–27, Berlin, Heidelberg, 2007.

Springer-Verlag. 2.2, 2.3, 2.3, 2.4, 3, 3.1, 4.2

[Ste82] Guy L. Steele, Jr. An overview of Common LISP. In Proceedings of

the 1982 ACM Symposium on LISP and Functional Programming,

LFP ’82, pages 98–107, New York, NY, USA, 1982. ACM. 2.1

[SVB13] Jeremy G. Siek, Michael M. Vitousek, and Shashank Bharadwaj.

Gradual typing for mutable objects. Technical report, University

of Colorado, 2013. [to be published]. 3, 3.1, 4.2

[SVCB15] Jeremy G. Siek, Michael M. Vitousek, Matteo Cimini, and

John Tang Boyland. Refined criteria for gradual typing. In

Thomas Ball, Rastislav Bodik, Shriram Krishnamurthi, Ben-

jamin S. Lerner, and Greg Morrisett, editors, 1st Summit on Ad-

vances in Programming Languages (SNAPL 2015), volume 32 of

Leibniz International Proceedings in Informatics (LIPIcs), pages

274–293, Dagstuhl, Germany, 2015. Schloss Dagstuhl–Leibniz-

Zentrum fuer Informatik. 2.4

[SW10] Jeremy G. Siek and Philip Wadler. Threesomes, with and without

blame. In Proceedings of the 37th Annual ACM SIGPLAN-

SIGACT Symposium on Principles of Programming Languages,

POPL ’10, pages 365–376, New York, NY, USA, 2010. ACM. 2.3

[Tan07] Audrey Tang. Perl 6: Reconciling the irreconcilable. In Proceed-

ings of the 34th Annual ACM SIGPLAN-SIGACT Symposium on

Principles of Programming Languages, POPL ’07, page 1, New

York, NY, USA, 2007. ACM. 2.3

[Tha90] Satish Thatte. Quasi-static typing. In Proceedings of the 17th

ACM SIGPLAN-SIGACT Symposium on Principles of Program-

ming Languages, POPL ’90, pages 367–381, New York, NY, USA,

1990. ACM. 2.1, 2.3

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 8:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Bibliography 118

[THF06] Sam Tobin-Hochstadt and Matthias Felleisen. Interlanguage mi-

gration: From scripts to programs. In Companion to the 21st ACM

SIGPLAN Symposium on Object-oriented Programming Systems,

Languages, and Applications, OOPSLA ’06, pages 964–974, New

York, NY, USA, 2006. ACM. 1, 2.4

[THF08] Sam Tobin-Hochstadt and Matthias Felleisen. The design and

implementation of Typed Scheme. In Proceedings of the 35th

Annual ACM SIGPLAN-SIGACT Symposium on Principles of

Programming Languages, POPL ’08, pages 395–406, New York,

NY, USA, 2008. ACM. 2.4, 6.2

[THF10] Sam Tobin-Hochstadt and Matthias Felleisen. Logical types for

untyped languages. In Proceedings of the 15th ACM SIGPLAN

International Conference on Functional Programming, ICFP ’10,

pages 117–128, New York, NY, USA, 2010. ACM. 3.3, 6.2

[Vit13] Michael Vitousek. Reticulated Python. https://github.com/

mvitousek/reticulated, 2013. [Accessed Februrary 2015]. 2.3

[VKSB14] Michael M. Vitousek, Andrew M. Kent, Jeremy G. Siek, and Jim

Baker. Design and evaluation of gradual typing for Python. In

Proceedings of the 10th ACM Symposium on Dynamic Languages,

DLS ’14, pages 45–56, New York, NY, USA, 2014. ACM. 2.3, 6.2

[vR14] Guido van Rossum. PEP483 - The Theory of Type Hints. https:

//www.python.org/dev/peps/pep-0483/, 2014. [Accessed Feb-

rurary 2015]. 6.2

[vRLL14] Guido van Rossum, Jukka Lehtosalo, and Lukasz Langa. PEP484

- Type Hints. https://www.python.org/dev/peps/pep-0484/,

2014. [Accessed Februrary 2015]. 6.2

[WF09] Philip Wadler and Robert Bruce Findler. Well-typed programs

can’t be blamed. In Proceedings of the 18th European Symposium

on Programming Languages and Systems: Held As Part of the

Joint European Conferences on Theory and Practice of Software,

ETAPS 2009, ESOP ’09, pages 1–16, Berlin, Heidelberg, 2009.

Springer-Verlag. 2.3

[Win11] Johnni Winther. Guarded type promotion: Eliminating redundant

casts in Java. In Proceedings of the 13th Workshop on Formal

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 9:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Bibliography 119

Techniques for Java-Like Programs, FTfJP ’11, pages 6:1–6:8,

New York, NY, USA, 2011. ACM. 6.2

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 10:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

AGlossary

bottom type A type that is subtype of all types.

closed table type A table type that does not provide any guarantees about

keys with types not listed in the table type. See complete definition in

page 63.

coercion A relation that allows converting values from one type to values of

another type without error.

consistency A relation used by gradual typing to check the interaction

between the dynamic type and other types. See complete definition in

page 18.

consistent-subtyping A relation that combines consistency and subtyping.

See complete definition in page 20.

contravariant A part of a type constructor is contravariant when it reverses

the subtyping order, that is, the part T1 of a type being a subtype of the

corresponding part T2 of another type implies that T2 <: T1.

covariant A part of a type constructor is covariant when it preserves the

subtyping order, that is, the part T1 of a type being a subtype of the

corresponding part T2 of another type implies that T1 <: T2.

depth subtyping A subtyping relation over records that allows variance in

the type of record fields.

dynamic type A type used by gradual typing to denote unknown values. See

complete definition in page 18.

filter type A type used by Typed Lua to discriminate the type of local

variables inside control flow statements. See complete definition in page

65.

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 11:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix A. Glossary 121

fixed table type A table type which guarantees that there are no keys with

a type that is not one of its key types, and that can have any number of

fixed or closed references. See complete definition in page 63.

flow typing An approach that combines static typing and flow analysis to

allow variables to have different types at different parts of the program.

free assigned variable A free variable that appears in an assignment.

gradual type system A type system that uses either the consistency relation

or the consistent-subtyping relation instead of type equality to perform

static type checking. See complete definition in page 18.

gradual typing An approach that uses a gradual type system to allow static

and dynamic typing in the same code, but inserting run-time checks

between statically typed and dynamically typed code. See complete

definition in page 18.

invariant A part of a type constructor is invariant when it forbids variance,

that is, the part T1 of a type being a subtype of the corresponding part

T2 of another type implies that T1 <: T2 and T2 <: T1. It is also a way

to define type equality through subtyping.

metatable A Lua table that allows changing the behavior of other tables it

is attached to.

nominal type system A type system that uses the type names to check the

compatibility among them.

open table type A table type which guarantees that there are no keys with a

type that is not one of its key types, and that only have closed references.

See complete definition in page 63.

optional type system A type system that allows combining static and

dynamic typing in the same language, but without affecting the run-

time semantics. See complete definition in page 17.

projection environment An environment used by Typed Lua to handle

unions of second-level types that are bound to projection types.

projection type A type used by Typed Lua to discriminate the type of local

variables that have a dependency relation. See complete definition in

page 65.

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 12:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix A. Glossary 122

prototype object An object that works like a class, that is, it is an object

from which other objects inherit its attributes.

self-like delegation A technique to implement inheritance in dynamically

typed languages through prototype objects.

sound type system A type system that does not type check all programs

that contain a type error.

structural type system A type system that uses type structures to check

the compatibility among them.

table refinement An operation from Typed Lua that allows programmers to

change a table type to include new fields or to specialize existing fields.

See complete definition in page 80.

top type A type that is supertype of all types.

type environment An environment that binds variable names to types.

type tag A tag that describes the type of a value during run-time in dynam-

ically typed languages.

unique table type A table type which guarantees that there are no keys with

a type that is not one of its key types, and that has only one reference.

See complete definition in page 63.

unsound type system A type system that type checks certain programs

that contain type errors.

userdata A Lua data type that allows Lua to hold values from applications

or libraries that are written in C.

vararg expression A Lua expression that can result in an arbitrary number

of values.

variadic function A function that can use an arbitrary number of arguments.

variance A property that defines the subtyping order between the compon-

ents of a type constructor.

width subtyping A subtyping relation over records that allows the subtype

to include fields that do not exist in the supertype.

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 13:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

BThe syntax of Typed Lua

This appendix presents the complete syntax of Typed Lua.

chunk ::= block

block ::= {stat} [retstat]

stat ::= ‘;’

| varlist ‘=’ explist

| functioncall

| label

| break

| goto Name

| do block end

| while exp do block end

| repeat block until exp

| if exp then block {elseif exp then block} [else block] end

| for Name ‘=’ exp ‘,’ exp [‘,’ exp] do block end

| for namelist in explist do block end

| [const] function funcname funcbody

| local function Name funcbody

| local namelist [‘=’ explist]

| [local] typealias Name ‘=’ type

| [local] interface typedec

retstat ::= return [explist] [‘;’]

label ::= ‘::’ Name ‘::’

funcname ::= Name {‘.’ Name} [‘:’ Name]

varlist ::= [const] var {‘,’ [const] var}

var ::= Name | prefixexp ‘[’ exp ‘]’ | prefixexp ‘.’ Name

namelist ::= Name [‘:’ type] {‘,’ Name [‘:’ type]}

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 14:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix B. The syntax of Typed Lua 124

explist ::= exp {‘,’ exp}

exp ::= nil | false | true | Number | String | ‘...’ | functiondef

| prefixexp | tableconstructor | exp binop exp | unop exp

prefixexp ::= var | functioncall | ‘(’ exp ‘)’

functioncall ::= prefixexp args | prefixexp ‘:’ Name args

args ::= ‘(’ [explist] ‘)’ | tableconstructor | String

functiondef ::= function funcbody

funcbody ::= ‘(’ [parlist] ‘)’ [‘:’ rettype] block end

parlist ::= namelist [‘,’ ‘...’ [‘:’ type]] | ‘...’ [‘:’ type]

tableconstructor ::= ‘{’ [fieldlist] ‘}’

fieldlist ::= [const] field {fieldsep [const] field} [fieldsep]

field ::= ‘[’ exp ‘]’ ‘=’ exp | Name ‘=’ exp | exp

fieldsep ::= ‘,’ | ‘;’

binop ::= ‘+’ | ‘-’ | ‘*’ | ‘/’ | ‘//’ | ‘^’ | ‘%’

| ‘&’ | ‘~’ | ‘|’ | ‘>>’ | ‘<<’ | ‘..’

| ‘<’ | ‘<=’ | ‘>’ | ‘>=’ | ‘==’ | ‘~=’

| and | or

unop ::= ‘-’ | not | ‘#’ | ‘~’

typedec ::= Name {decitem} end

decitem ::= idlist ‘:’ idtype

idtype ::= type | methodtype

idlist ::= id {‘,’ id}

id ::= [const] Name

type ::= primarytype [‘?’]

primarytype ::= literaltype | basetype | nil | value | any | self | Name

| functiontype | tabletype | primarytype ‘|’ primarytype

literaltype ::= false | true | Int | Float | String

basetype ::= boolean | integer | number | string

functiontype ::= tupletype ‘->’ rettype

tupletype ::= ‘(’ [typelist] ‘)’

typelist ::= type {‘,’ type} [‘*’]

rettype ::= type | uniontuple [‘?’]

uniontuple ::= tupletype | uniontuple ‘|’ uniontuple

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 15:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix B. The syntax of Typed Lua 125

tabletype ::= ‘{’ [tabletypebody] ‘}’

tabletypebody ::= maptype | recordtype

maptype ::= [keytype ‘:’] type

keytype ::= basetype | value

recordtype ::= recordfield {‘,’ recordfield} [‘,’ type]

recordfield ::= [const] literaltype ‘:’ type

methodtype ::= tupletype ‘=>’ rettype

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 16:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

CThe type system of Typed Lua

This appendix presents the complete type system of Typed Lua.

C.1 Subtyping rules

(S-LITERAL)

Σ ` L <: L

(S-FALSE)

Σ ` false <: boolean

(S-TRUE)

Σ ` true <: boolean

(S-STRING)

Σ ` string <: string

(S-INT1)

Σ ` int <: integer

(S-INT2)

Σ ` int <: number

(S-FLOAT)

Σ ` float <: number

(S-BASE)

Σ ` B <: B

(S-INTEGER)

Σ ` integer <: number

(S-NIL)

Σ ` nil <: nil

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 17:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 127

(S-VALUE)

Σ ` F <: value

(S-ANY)

Σ ` any <: any

(S-SELF)

Σ ` self <: self

(S-UNION1)Σ ` F1 <: F Σ ` F2 <: F

Σ ` F1 ∪ F2 <: F

(S-UNION2)Σ ` F <: F1

Σ ` F <: F1 ∪ F2

(S-UNION3)Σ ` F <: F2

Σ ` F <: F1 ∪ F2

(S-FUNCTION)

Σ ` S3 <: S1 Σ ` S2 <: S4

Σ ` S1 → S2 <: S3 → S4

(S-PAIR)Σ ` F1 <: F2 Σ ` P1 <: P2

Σ ` F1 × P1 <: F2 × P2

(S-VARARG1)

Σ ` F1 ∪ nil <: F2 ∪ nil

Σ ` F1∗ <: F2∗

(S-VARARG2)

Σ ` F1 ∪ nil <: F2 Σ ` F1∗ <: P2

Σ ` F1∗ <: F2 × P2

(S-VARARG3)

Σ ` F1 <: F2 ∪ nil Σ ` P1 <: F2∗Σ ` F1 × P1 <: F2∗

(S-UNION4)Σ ` S1 <: S Σ ` S2 <: S

Σ ` S1 t S2 <: S

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 18:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 128

(S-UNION5)Σ ` S <: S1

Σ ` S <: S1 t S2

(S-UNION6)Σ ` S <: S2

Σ ` S <: S1 t S2

(S-TABLE1)

∀i ∃j Σ ` Fj <: F ′i Σ ` F ′

i <: Fj Σ ` Vj <:c V′i

Σ ` {F :V }fixed|closed <: {F ′:V ′}closed

(S-TABLE2)

∀i ∀j Σ ` Fi <: F ′j → Σ ` Vi <:u V

′j

∀j @i Σ ` Fi <: F ′j → Σ ` nil <:o V

′j

Σ ` {F :V }unique <: {F ′:V ′}closed

(S-TABLE3)

∀i ∃j Σ ` Fi <: F ′j ∧ Σ ` Vi <:u V

′j

∀j @i Σ ` Fi <: F ′j → Σ ` nil <:o V

′j

Σ ` {F :V }unique <: {F ′:V ′}unique|open|fixed

(S-TABLE4)

∀i ∀j Σ ` Fi <: F ′j → Σ ` Vi <:c V

′j

∀j @i Σ ` Fi <: F ′j → Σ ` nil <:o V

′j

Σ ` {F :V }open <: {F ′:V ′}closed

(S-TABLE5)

∀i ∃j Σ ` Fi <: F ′j ∧ Σ ` Vi <:c V

′j

∀j @i Σ ` Fi <: F ′j → Σ ` nil <:o V

′j

Σ ` {F :V }open <: {F ′:V ′}open|fixed

(S-TABLE6)

∀i ∃j Σ ` Fi <: F ′j Σ ` F ′

j <: Fi Σ ` Vi <:c V′j

∀j ∃i Σ ` Fi <: F ′j Σ ` F ′

j <: Fi Σ ` Vi <:c V′j

Σ ` {F :V }fixed <: {F ′:V ′}fixed

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 19:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 129

(S-FIELD1)Σ ` F1 <: F2 Σ ` F2 <: F1

Σ ` F1 <:c F2

(S-FIELD2)Σ ` F1 <: F2

Σ ` const F1 <:c const F2

(S-FIELD3)Σ ` F1 <: F2

Σ ` F1 <:c const F2

(S-FIELD4)Σ ` F1 <: F2

Σ ` F1 <:u F2

(S-FIELD5)Σ ` F1 <: F2

Σ ` const F1 <:u const F2

(S-FIELD6)Σ ` F1 <: F2

Σ ` const F1 <:u F2

(S-FIELD7)Σ ` F1 <: F2

Σ ` F1 <:u const F2

(S-FIELD8)Σ ` nil <: F

Σ ` nil <:o F

(S-FIELD9)Σ ` nil <: F

Σ ` nil <:o const F

(S-AMBER)Σ[x1 <: x2] ` F1 <: F2

Σ ` µx1.F1 <: µx2.F2

(S-ASSUMPTION)x1 <: x2 ∈ Σ

Σ ` x1 <: x2

(S-UNFOLDR)

Σ ` F1 <: [x 7→ µx.F2]F2

Σ ` F1 <: µx.F2

(S-UNFOLDL)

Σ ` [x 7→ µx.F1]F1 <: F2

Σ ` µx.F1 <: F2

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 20:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 130

(S-EXPRESSION)

Σ ` T <: T

(S-PAIR2)Σ ` T1 <: T2 Σ ` E1 <: E2

Σ ` T1 × E1 <: T2 × E2

(S-VARARG4)Σ ` T1 ∪ nil <: T2 ∪ nil

Σ ` T1∗ <: T2∗

(S-VARARG5)

Σ ` T1 ∪ nil <: T2 Σ ` T1∗ <: E2

Σ ` T1∗ <: T2 × E2

(S-VARARG6)

Σ ` T1 <: T2 ∪ nil Σ ` E1 <: T2∗Σ ` T1 × E1 <: T2∗

(C-ANY1)

Σ ` F . any

(C-ANY2)

Σ ` any . F

C.2 Typing rules

(T-SKIP)

Γ1,Π ` skip,Γ1

(T-SEQ)Γ1,Π ` s1,Γ2 Γ2,Π ` s2,Γ3

Γ1,Π ` s1 ; s2,Γ3

(T-ASSIGNMENT)

Γ1,Π ` el : S1,Γ2 Γ2,Π ` l : S2,Γ3 S1 . S2

Γ1,Π ` l = el,Γ3

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 21:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 131

(T-METHOD1)

Γ1(id1) = Fs Fs = {F :V }uniqueΓ1,Π ` id2 : L,Γ2 @i ∈ 1..n L . Fi n = |F :V |

closeall(Γ1)[self 7→ self , id 7→ F , σ 7→ Fs],Π[ρ 7→ S] ` s,Γ3

Fo = {F :V , L:const self × F1 × ...× Fn × nil∗ → S}uniqueΓ4 = openset(Γ1[id1 7→ Fo], frv(fun (id:T ):S s))

Γ5 = closeset(Γ4, fav(fun (id:T ):S s))

Γ1,Π ` fun id1:id2 (id:F ):S s,Γ5

(T-METHOD2)

Γ1(id1) = Fs Fs = {F :V }openΓ1,Π ` id2 : L,Γ2 @i ∈ 1..n L . Fi n = |F :V |

closeall(Γ1)[self 7→ self , id 7→ F , σ 7→ Fs],Π[ρ 7→ S] ` s,Γ3

Fo = {F :V , L:const self × F1 × ...× Fn × nil∗ → S}openΓ4 = openset(Γ1[id1 7→ Fo], frv(fun (id:T ):S s))

Γ5 = closeset(Γ4, fav(fun (id:T ):S s))

Γ1,Π ` fun id1:id2 (id:F ):S s,Γ5

(T-METHOD3)

Γ1(id1) = Fs Fs = {F :V }uniqueΓ1,Π ` id2 : L,Γ2 @i ∈ 1..n L . Fi n = |F :V |

closeall(Γ1)[self 7→ self , id 7→ F , ... 7→ F, σ 7→ Fs],Π[ρ 7→ S] ` s,Γ3

Fo = {F :V , L:const self × F1 × ...× Fn × F∗ → S}uniqueΓ4 = openset(Γ1[id1 7→ Fo], frv(fun (id:T ):S s))

Γ5 = closeset(Γ4, fav(fun (id:T ):S s))

Γ1,Π ` fun id1:id2 (id:F , ...:F ):S s,Γ5

(T-METHOD4)

Γ1(id1) = Fs Fs = {F :V }openΓ1,Π ` id2 : L,Γ2 @i ∈ 1..n L . Fi n = |F :V |

closeall(Γ1)[self 7→ self , id 7→ F , ... 7→ F, σ 7→ Fs],Π[ρ 7→ S] ` s,Γ3

Fo = {F :V , L:const self × F1 × ...× Fn × F∗ → S}openΓ4 = openset(Γ1[id1 7→ Fo], frv(fun (id:T ):S s))

Γ5 = closeset(Γ4, fav(fun (id:T ):S s))

Γ1,Π ` fun id1:id2 (id:F , ...:F ):S s,Γ5

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 22:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 132

(T-METHOD5)

Γ1(id1) = Fs Fs = {F :V }unique Γ1,Π ` id2 : L,Γ2 n = |F :V |∃i ∈ 1..n L <: Fi ∧ Fi <: L ∧ const self × F1 × ...× Fn × nil∗ → S <: Vi

closeall(Γ1)[self 7→ self , id 7→ F , σ 7→ Fs],Π[ρ 7→ S] ` s,Γ3

Vi 7→ const self × F1 × ...× Fn × nil∗ → S

Γ4 = openset(Γ1[id1 7→ Fs], frv(fun (id:T ):S s))

Γ5 = closeset(Γ4, fav(fun (id:T ):S s))

Γ1,Π ` fun id1:id2 (id:F ):S s,Γ5

(T-METHOD6)

Γ1(id1) = Fs Fs = {F :V }open Γ1,Π ` id2 : L,Γ2 n = |F :V |∃i ∈ 1..n L <: Fi ∧ Fi <: L ∧ const self × F1 × ...× Fn × nil∗ → S <: Vi

closeall(Γ1)[self 7→ self , id 7→ F , σ 7→ Fs],Π[ρ 7→ S] ` s,Γ3

Vi 7→ const self × F1 × ...× Fn × nil∗ → S

Γ4 = openset(Γ1[id1 7→ Fs], frv(fun (id:T ):S s))

Γ5 = closeset(Γ4, fav(fun (id:T ):S s))

Γ1,Π ` fun id1:id2 (id:F ):S s,Γ5

(T-METHOD7)

Γ1(id1) = Fs Fs = {F :V }unique Γ1,Π ` id2 : L,Γ2 n = |F :V |∃i ∈ 1..n L <: Fi ∧ Fi <: L ∧ const self × F1 × ...× Fn × F∗ → S <: Vi

closeall(Γ1)[self 7→ self , id 7→ F , ... 7→ F, σ 7→ Fs],Π[ρ 7→ S] ` s,Γ3

Vi 7→ const self × F1 × ...× Fn × F∗ → S

Γ4 = openset(Γ1[id1 7→ Fs], frv(fun (id:T ):S s))

Γ5 = closeset(Γ4, fav(fun (id:T ):S s))

Γ1,Π ` fun id1:id2 (id:F , ...:F ):S s,Γ5

(T-METHOD8)

Γ1(id1) = Fs Fs = {F :V }open Γ1,Π ` id2 : L,Γ2 n = |F :V |∃i ∈ 1..n L <: Fi ∧ Fi <: L ∧ const self × F1 × ...× Fn × F∗ → S <: Vi

closeall(Γ1)[self 7→ self , id 7→ F , ... 7→ F, σ 7→ Fs],Π[ρ 7→ S] ` s,Γ3

Vi 7→ const self × F1 × ...× Fn × F∗ → S

Γ4 = openset(Γ1[id1 7→ Fs], frv(fun (id:T ):S s))

Γ5 = closeset(Γ4, fav(fun (id:T ):S s))

Γ1,Π ` fun id1:id2 (id:F , ...:F ):S s,Γ5

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 23:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 133

(T-WHILE1)

Γ1,Π ` e : F,Γ2 closeall(Γ2),Π ` s,Γ3

Γ4 = closeset(Γ2, fav(s))

Γ5 = openset(Γ4, frv(s))

Γ1,Π ` while e do s,Γ5

(T-WHILE2)

Γ1(id) = F

closeall(Γ1[id 7→ φ(F, filter(F,nil))]),Π ` s,Γ2

Γ3 = openset(Γ1[id 7→ F ], frv(s))

Γ4 = closeset(Γ3, fav(s))

Γ1,Π ` while id do s,Γ4

(T-IF1)

Γ1,Π ` e : T,Γ2 Γ2,Π ` s1 : Γ3 Γ2,Π ` s2 : Γ4 Γ5 = join(Γ3,Γ4)

Γ1 ` if e then s1 else s2,Γ5

(T-IF2)

Γ1(id) = F Ft = fot(F,nil) Fe = fit(F,nil)

Γ1[id 7→ φ(F, Ft)],Π ` s1,Γ2

Γ1[id 7→ φ(F, Fe)],Π ` s2,Γ3

Γ4 = join(Γ2,Γ3)

Γ1,Π ` if id then s1 else s2,Γ4[id 7→ F ]

(T-IF3)

Γ1(id) = F Ft = fot(F,nil) Fe = fit(F,nil)

Fe = void Γ1[id 7→ φ(F, Ft)],Π ` s1,Γ2

Γ1,Π ` if id then s1 else s2,Γ2[id 7→ F ]

(T-IF4)

Γ1(id) = F Ft = fot(F,nil) Fe = fit(F,nil)

Ft = void Γ1[id 7→ φ(F, Fe)],Π ` s2,Γ2

Γ1,Π ` if id then s1 else s2,Γ2[id 7→ F ]

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 24:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 134

(T-IF5)

Γ1(id) = πxi

St = fopt(Π(x),nil, i) Se = fipt(Π(x),nil, i)

Γ1,Π[x 7→ St] ` s1,Γ2

Γ1,Π[x 7→ Se] ` s2,Γ3

Γ4 = join(Γ2,Γ3)

Γ1,Π ` if id then s1 else s2,Γ4

(T-IF6)

Γ1(id) = πxi

St = fopt(Π(x),nil, i)

fit(proj(Π(x), i),nil) = void

Γ1,Π[x 7→ St] ` s1,Γ2

Γ1,Π ` if id then s1 else s2,Γ2

(T-IF7)

Γ1(id) = πxi

Se = fipt(Π(x),nil, i)

fot(proj(Π(x), i),nil) = void

Γ1,Π[x 7→ Se] ` s2,Γ2

Γ1,Π ` if id then s1 else s2,Γ2

(T-IF8)

Γ1(id) = φ(F1, F2) Ft = fit(F2, string) Fe = fot(F2, string)

Γ1[id 7→ φ(F1, Ft)],Π ` s1,Γ2

Γ1[id 7→ φ(F1, Fe)],Π ` s2,Γ3

Γ4 = join(Γ2,Γ3)

Γ1,Π ` if type(id) == “string” then s1 else s2,Γ4[id 7→ F1]

(T-IF9)

Γ1(id) = φ(F1, F2) Ft = fit(F2, string) Fe = fot(F2, string)

Ft = void Γ1[id 7→ φ(F1, Fe)],Π ` s2,Γ2

Γ1,Π ` if type(id) == “string” then s1 else s2,Γ2[id 7→ F1]

(T-IF10)

Γ1(id) = φ(F1, F2) Ft = fit(F2, string) Fe = fot(F2, string)

Fe = void Γ1[id 7→ φ(F1, Ft)],Π ` s1,Γ2

Γ1,Π ` if type(id) == “string” then s1 else s2,Γ2[id 7→ F1]

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 25:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 135

(T-LOCAL1)

Γ1,Π ` el : S,Γ2

S . F1 × ...× Fn × value∗ n = | id:F |Γ2[id 7→ F ],Π ` s,Γ3

Γ1,Π ` local id:F = el in s, (Γ3 − {id})[id 7→ Γ2(id)]

(T-LOCAL2)

Γ1,Π ` el : E,Γ2, (x, S)

Γ3 = Γ2[id1 7→ infer(E, 1), ..., idn 7→ infer(E, n)]

Γ3,Π[x 7→ S] ` s,Γ4 n = | id |Γ1,Π ` local id = el in s, (Γ4 − {id})[id 7→ Γ2(id)]

(T-LOCALREC)

Γ1[id 7→ F ],Π ` e : F1,Γ2 F1 . F Γ2,Π ` s,Γ3

Γ1,Π ` rec id:F = e in s, (Γ3 − {id})[id 7→ Γ2(id)]

(T-RETURN)

Γ1 ` el : S1,Γ2 Π(ρ) = S2 S1 . S2

Γ1 ` return el,Γ2

(T-STMAPPLY1)

Γ1,Π ` e(el) : S,Γ2

Γ1,Π ` be(el)c0,Γ2

(T-STMINVOKE1)

Γ1,Π ` e:n(el) : S,Γ2

Γ1,Π ` be:n(el)c0,Γ2

(T-NIL)

Γ1,Π ` nil : nil,Γ1

(T-FALSE)

Γ1,Π ` false : false,Γ1

(T-TRUE)

Γ1,Π ` true : true,Γ1

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 26:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 136

(T-INT)

Γ1,Π ` int : int ,Γ1

(T-FLOAT)

Γ1,Π ` float : float ,Γ1

(T-STR)

Γ1,Π ` string : string ,Γ1

(T-IDREAD1)

Γ1(id) = F

Γ1,Π ` id : close(F ),Γ1[id 7→ open(F )]

(T-IDREAD2)

Γ1(id) = F

Γ1,Π ` id : fix(F ),Γ1[id 7→ fix(F )]

(T-IDREAD3)Γ1(id) = φ(F1, F2)

Γ1,Π ` id : F2,Γ1

(T-IDREAD4)

Γ1(id) = πxi

Γ1,Π ` id : proj(Π(x), i),Γ1

(T-INDEXREAD1)

Γ1(id) = {F :V } Γ1,Π ` e2 : F,Γ2 ∃i ∈ 1..n F . Fi n = |F :V |Γ1,Π ` id[e2] : rconst(Vi),Γ2

(T-INDEXREAD2)

Γ1,Π ` e1 : {F :V },Γ2 Γ2,Π ` e2 : F,Γ3 ∃i ∈ 1..n F . Fi n = |F :V |Γ1,Π ` e1[e2] : rconst(Vi),Γ3

(T-INDEXREAD3)

Γ1,Π ` e1 : any,Γ2 Γ2,Π ` e2 : F,Γ3

Γ1,Π ` e1[e2] : any,Γ3

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 27:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 137

(T-COERCE1)

Γ1(id) <: F tag(F, closed)

Γ1,Π ` <F> id : F,Γ1[id 7→ reopen(F )]

(T-COERCE2)

Γ1(id) <: F tag(F, fixed)

Γ1,Π ` <F> id : F,Γ1[id 7→ F ]

(T-FUNCTION1)

closeall(Γ1)[id 7→ F ],Π[ρ 7→ S] ` s,Γ2

Γ3 = openset(Γ1, frv(fun (id:F ):S s))

Γ4 = closeset(Γ3, fav(fun (id:F ):S s))

Γ1,Π ` fun (id:F ):S s : F1 × ...× Fn × nil∗ → S,Γ4

(T-FUNCTION2)

closeall(Γ1)[id 7→ F , ... 7→ F ],Π[ρ 7→ S] ` s,Γ2

Γ3 = openset(Γ1, frv(fun (id:F ):S s))

Γ4 = closeset(Γ3, fav(fun (id:F ):S s))

Γ1,Π ` fun (id:F , ...:F ):S s : F1 × ...× Fn × F∗ → S,Γ4

(T-CONSTRUCTOR1)

Γ1,Π ` ([e1] = e2)i : (Fi, Vi),Γi+1 T = {F1:V1, ..., Fn:Vn}uniquewf(T ) n = | [e1] = e2 | Γf = merge(Γ1, ...,Γn+1)

Γ1,Π ` { [e1] = e2 } : T,Γf

(T-CONSTRUCTOR2)

Γ1,Π ` ([e1] = e2)i : (Fi, Vi),Γi+1

Γ1,Π ` me : Fn+1 × ...× Fn+m × Fn+m+1∗,Γn+2

T = {F1:V1, ..., Fn:Vn, 1:Fn+1, ...,m:Fn+m, integer:Fn+m+1 ∪ nil}uniquewf(T ) n = | [e1] = e2 | Γf = merge(Γ1, ...,Γn+2)

Γ1,Π ` { [e1] = e2 } : T,Γf

(T-FIELD)

Γ1,Π ` e2 : V,Γ2 Γ2,Π ` e1 : F,Γ3

Γ1,Π ` [e1] = e2 : (F, vt(F, V )),Γ3

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 28:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 138

(T-ARITH1)

Γ1,Π ` e1 : F1,Γ2 Γ2,Π ` e2 : F2,Γ3 F1 <: integer F2 <: integer

Γ1,Π ` e1 + e2 : integer,Γ3

(T-ARITH2)

Γ1,Π ` e1 : F1,Γ2 Γ2,Π ` e2 : F2,Γ3 F1 <: integer F2 <: number

Γ1,Π ` e1 + e2 : number,Γ3

(T-ARITH3)

Γ1,Π ` e1 : F1,Γ2 Γ2,Π ` e2 : F2,Γ3 F1 <: number F2 <: integer

Γ1,Π ` e1 + e2 : number,Γ3

(T-ARITH4)

Γ1,Π ` e1 : F1,Γ2 Γ2,Π ` e2 : F2,Γ3 F1 <: number F2 <: number

Γ1,Π ` e1 + e2 : number,Γ3

(T-ARITH5)

Γ1,Π ` e1 : any,Γ2 Γ2,Π ` e2 : F,Γ3

Γ1,Π ` e1 + e2 : any,Γ3

(T-ARITH6)

Γ1,Π ` e1 : F,Γ2 Γ2,Π ` e2 : any,Γ3

Γ1,Π ` e1 + e2 : any,Γ3

(T-CONCAT1)

Γ1,Π ` e1 : F1,Γ2 Γ2,Π ` e2 : F2,Γ3 F1 <: string F2 <: string

Γ1,Π ` e1 .. e2 : string,Γ3

(T-CONCAT2)

Γ1,Π ` e1 : any,Γ2 Γ2,Π ` e2 : F,Γ3

Γ1,Π ` e1 .. e2 : any,Γ3

(T-CONCAT3)

Γ1,Π ` e1 : F,Γ2 Γ2,Π ` e2 : any,Γ3

Γ1,Π ` e1 .. e2 : any,Γ3

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 29:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 139

(T-EQUAL)

Γ1,Π ` e1 : F1,Γ2 Γ2,Π ` e2 : F2,Γ3

Γ1,Π ` e1 == e2 : boolean,Γ3

(T-ORDER1)

Γ1,Π ` e1 : F1,Γ2 Γ2,Π ` e2 : F2,Γ3 F1 <: number F2 <: number

Γ,Π ` e1 < e2 : boolean,Γ3

(T-ORDER2)

Γ1,Π ` e1 : F1,Γ2 Γ2,Π ` e2 : F2,Γ3 F1 <: string F2 <: string

Γ1,Π ` e1 < e2 : boolean

(T-ORDER3)

Γ1,Π ` e1 : any,Γ2 Γ2,Π ` e2 : F,Γ3

Γ1,Π ` e1 < e2 : any,Γ3

(T-ORDER4)

Γ1,Π ` e1 : F,Γ2 Γ2,Π ` e2 : any,Γ3

Γ1,Π ` e1 < e2 : any,Γ3

(T-BITWISE1)

Γ1,Π ` e1 : F1,Γ2 Γ2,Π ` e2 : F2,Γ3 F1 <: integer F2 <: integer

Γ1,Π ` e1 & e2 : integer,Γ3

(T-BITWISE2)

Γ1,Π ` e1 : any,Γ2 Γ2,Π ` e2 : F,Γ3

Γ1,Π ` e1 & e2 : any,Γ3

(T-BITWISE3)

Γ1,Π ` e1 : F,Γ2 Γ2,Π ` e2 : any,Γ3

Γ1,Π ` e1 & e2 : any,Γ3

(T-AND1)Γ1,Π ` e1 : nil,Γ2

Γ1,Π ` e1 and e2 : nil,Γ2

(T-AND2)Γ1,Π ` e1 : false,Γ2

Γ1,Π ` e1 and e2 : false,Γ2

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 30:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 140

(T-AND3)Γ1,Π ` e1 : nil ∪ false,Γ2

Γ1,Π ` e1 and e2 : nil ∪ false,Γ2

(T-AND4)

Γ1,Π ` e1 : F1,Γ2 Γ2,Π ` e2 : F2,Γ3 nil 6. F1 false 6. F1

Γ1,Π ` e1 and e2 : F2,Γ3

(T-AND5)

Γ1,Π ` e1 : F1,Γ2 Γ2,Π ` e2 : F2,Γ3

Γ1,Π ` e1 and e2 : F1 ∪ F2,Γ3

(T-OR1)

Γ1,Π ` e1 : F,Γ2 nil 6. F false 6. F

Γ1,Π ` e1 or e2 : F,Γ2

(T-OR2)Γ1,Π ` e1 : nil,Γ2 Γ2,Π ` e2 : F,Γ3

Γ1,Π ` e1 or e2 : F,Γ3

(T-OR3)

Γ1,Π ` e1 : false,Γ2 Γ2,Π ` e2 : F,Γ3

Γ1,Π ` e1 or e2 : F,Γ3

(T-OR4)

Γ1,Π ` e1 : nil ∪ false,Γ2 Γ2,Π ` e2 : F,Γ3

Γ1,Π ` e1 or e2 : F,Γ3

(T-OR5)

Γ1,Π ` e1 : F1,Γ2 Γ2,Π ` e2 : F2,Γ3

Γ1,Π ` e1 or e2 : filter(filter(F1,nil), false) ∪ F2,Γ3

(T-NOT1)Γ1,Π ` e : nil,Γ2

Γ1,Π ` not e : true,Γ2

(T-NOT2)Γ1,Π ` e : false,Γ2

Γ1,Π ` not e : true,Γ2

(T-NOT3)Γ1,Π ` e : nil ∪ false,Γ2

Γ1,Π ` not e : true,Γ2

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 31:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 141

(T-NOT4)

Γ1,Π ` e : F nil 6. F false 6. F

Γ1,Π ` not e : false,Γ2

(T-NOT5)Γ1,Π ` e : F,Γ2

Γ1,Π ` not e : boolean,Γ2

(T-LEN1)Γ1,Π ` e : F,Γ2 F <: string

Γ1,Π ` # e : integer,Γ2

(T-LEN2)Γ1,Π ` e : F,Γ2 F <: {}closed

Γ1,Π ` # e : integer,Γ2

(T-LEN3)Γ1,Π ` e : any,Γ2

Γ1,Π ` # e : any,Γ2

(T-EXPAPPLY1)

Γ1,Π ` e(el) : S,Γ2

Γ1,Π ` be(el)c1 : proj(S, 1),Γ2

(T-EXPINVOKE1)

Γ1,Π ` e:n(el) : S,Γ2

Γ1,Π ` be:n(el)c1 : proj(S, 1),Γ2

(T-EXPDOTS)

Γ1,Π ` ... : F∗,Γ2

Γ1,Π ` b...c1 : F ∪ nil,Γ2

(T-IDWRITE1)Γ1(id) = F

Γ1,Π ` idl : F,Γ1

(T-IDWRITE2)

Γ1(id) = φ(F1, F2)

Γ1,Π ` idl : F1,Γ1[id 7→ F1]

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 32:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 142

(T-INDEXWRITE1)

Γ1,Π ` e1 : {F :V },Γ2

Γ2,Π ` e2 : F,Γ3 ∃i ∈ 1..n F . Fi ∧ ¬const(Vi) n = |F :V |Γ1,Π ` e1[e2]l : Vi,Γ3

(T-INDEXWRITE2)

Γ1,Π ` e1 : any,Γ2 Γ2,Π ` e2 : F,Γ3

Γ1,Π ` e1[e2]l : any,Γ3

(T-REFINE1)

Γ1(id) = {F :V }uniqueΓ1,Π ` e : Fnew,Γ2 @i ∈ 1..n Fnew . Fi Vnew = vt(Fnew, V ) n = |F :V |

Γ1,Π ` id[e]<V > : Vnew,Γ2[id 7→ {F :V , Fnew:Vnew}unique]

(T-REFINE2)

Γ1(id) = {F :V }openΓ1,Π ` e : Fnew,Γ2 @i ∈ 1..n Fnew . Fi Vnew = vt(Fnew, V ) n = |F :V |

Γ1,Π ` id[e]<V > : Vnew,Γ2[id 7→ {F :V , Fnew:Vnew}open]

(T-LHSLIST)

Γ1,Π ` li : Fi,Γi+1 Γf = merge(Γ1, ...,Γn+1) n = | l |Γ1,Π ` l : F1 × ...× Fn × value∗,Γf

(T-EXPLIST1)

Γ1,Π ` ei : Fi,Γi+1 Γf = merge(Γ1, ...,Γn+1) n = | e |Γ1,Π ` e : F1 × ...× Fn × nil∗,Γf

(T-EXPLIST2)

Γ1,Π ` ei : Fi,Γi+1 Γ1,Π ` me : Fn+1 × ...× Fn+m × Fn+m+1∗,Γn+2

Γf = merge(Γ1, ...,Γn+2) n = | e |Γ1,Π ` e,me : F1 × ...× Fn+m × Fn+m+1∗,Γf

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 33:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 143

(T-EXPLIST3)

Γ1,Π ` ei : Fi,Γi+1 Γ1,Π ` me : S,Γn+2

S = Fn+1 × ...× Fn+m × nil∗ t F ′n+1 × ...× F ′

n+m × nil∗Γf = merge(Γ1, ...,Γn+2) n = | e |

Γ1,Π ` e,me : F1 × ...× Fn × πx1 × ...× πx

m × nil∗,Γf , (x, S)

(T-APPLY1)

Γ1,Π ` e : S1 → S2,Γ2 Γ2,Π ` el : S3,Γ3 S3 . S1

Γ1,Π ` e(el) : S2,Γ3

(T-APPLY2)

Γ1,Π ` e : any,Γ2 Γ2,Π ` el : S,Γ3

Γ1,Π ` e1(el) : any∗,Γ3

(T-INVOKE1)

Γ1,Π ` e : F,Γ2

Γ2[σ 7→ F ],Π ` e[id] : const S1 → S2,Γ3

Γ3[σ 7→ F ],Π ` el : S3,Γ4 F × S3 . [self 7→ F ]S1

Γ1,Π ` e:id(el) : [self 7→ F ]S2,Γ4

(T-INVOKE2)

Γ1,Π ` e : any,Γ2 Γ2,Π ` el : S,Γ3

Γ1,Π ` e:id(el) : any∗,Γ3

(T-DOTS)Γ1(...) = F

Γ1,Π ` ... : F∗,Γ1

(T-SELF)Γ1,Π ` e : self ,Γ2 Γ2(σ) = F

Γ1,Π ` e : F,Γ2

(T-SETMETATABLE1)

Γ1(id) = self

Γ1,Π ` setmetatable({}, {[“ index”] = id}) : self ,Γ1

(T-SETMETATABLE2)

Γ1(id) = {F1:V1, ..., Fn:Vn}fixedΓ1,Π ` setmetatable({}, {[“ index”] = id}) : {F1:V1, ..., Fn:Vn}open,Γ1

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 34:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 144

(T-SETMETATABLE3)

Γ1,Π ` e : T,Γ2 T = {F1:V1, ..., Fn:Vn}closed Γ1(id) = self Γ1(σ) <: T

Γ1,Π ` setmetatable(e, {[“ index”] = id}) : self ,Γ2[σ 7→ T ]

(T-UNFOLD)

Γ1,Π ` e : µx.F,Γ2

Γ1,Π ` e : [x 7→ µx.F ]F,Γ2

(T-FOLD)Γ1,Π ` e : [x 7→ µx.F ]F,Γ2

Γ1,Π ` e : µx.F,Γ2

(T-TERNARY)

Γ1,Π ` e1 : F1,Γ2 Γ2,Π ` e2 : F2,Γ3 Γ3,Π ` e3 : F2,Γ4

Γ1,Π ` e1 and e2 or e3 : F2,Γ4

C.3 Auxiliary functions

wf({F : V }unique|open|fixed|closed) = ∀i ((@j i 6= j ∧ Fi . Fj) ∧ wf(Vi)∧

¬tag(Vi, unique) ∧ ¬tag(Vi, open))

wf(const F ) = wf(F )

wf(F1 ∪ F2) = wf(F1) ∧ wf(F2)

wf(µx.F ) = wf(F )

wf(S1 → S2) = wf(S1) ∧ wf(S2)

wf(S1 t S2) = wf(S1) ∧ wf(S2)

wf(F∗) = wf(F )

wf(F × P ) = wf(F ) ∧ wf(P )

wf(F ) = > for all other cases

tag(F1 ∪ F2, t) = tag(F1, t) ∨ tag(F2, t)

tag({F :V }t, t) = >

tag({F :V }t1 , t2) = ⊥

tag(F, t) = ⊥

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 35:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 145

vt(L, V ) = fix(V )

vt(F1, F2) = nil(fix(F2))

vt(F1, const F2) = const nil(fix(F2))

nil(T ) =

{T if nil . T

T ∪ nil otherwise

fix(F1 ∪ F2) = fix(F1) ∪ fix(F2)

fix({F :V }unique|open) = {F :V }fixedfix(F ) = F

close(F1 ∪ F2) = close(F1) ∪ close(F2)

close({F :V }unique|open) = {F :V }closedclose(F ) = F

open(F1 ∪ F2) = open(F1) ∪ open(F2)

open({F :V }unique) = {F :V }openopen(F ) = F

reopen({F : V }closed) = {F : V }openreopen(F ) = F

rconst(const F ) = F

rconst(F ) = F

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 36:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 146

const(const F ) = >

const(F ) = ⊥

proj(S1 t S2, i) = proj(S1, i) ∪ proj(S2, i)

proj(F∗, i) = nil(F )

proj(F × P, 1) = F

proj(F × P, i) = proj(P, i− 1)

proj(E∗, i) = nil(E)

proj(T × E, 1) = T

proj(T × E, i) = proj(E, i− 1)

infer(T1 × ...× Tn∗, i) =

{general(Ti) if i < n

general(nil(Tn)) if i >= n

general(false) = boolean

general(true) = boolean

general(int) = integer

general(float) = number

general(string) = string

general(F1 ∪ F2) = general(F1) ∪ general(F2)

general(S1 → S2) = general2(S1)→ general2(S2)

general({F1:V1, ..., Fn:Vn}tag) = {F1:general(V1), ..., Fn:general(Vn)}taggeneral(µx.F ) = µx.general(F )

general(T ) = T

general2(F∗) = general(F )∗

general2(F × P ) = general(F )× general2(P )

general2(S1 t S2) = general2(S1) t general2(S2)

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 37:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 147

closeall(Γ[id1 7→ T1, ..., idn 7→ Tn]) = Γ[id1 7→ close(T1), ..., idn 7→ close(Tn)]

closeset(Γ, {id1, ..., idn}) = Γ[id1 7→ close(Γ(id1)), ..., idn 7→ close(Γ(idn))]

openset(Γ, {id1, ..., idn}) = Γ[id1 7→ open(Γ(id1)), ..., idn 7→ open(Γ(idn))]

merge(Γ) = reduce(Γ,merge2)

merge2(Γ1,Γ2) = {(id,merget(Γ1(id),Γ2(id))}

merget(T1, T2) = T1 if T2 . T1

merget(T1, T2) = T2 if T1 . T2

the next case applies if

V l .u Vr ∨ V r .u Vl

and the right side is wf

merget({F : V l, F ′ : V ′}unique,

{F : V r, F ′′ : V ′′}unique) = {F : supu(V l, V r),

F ′ : V ′,

F ′′ : V ′′}uniquethe next case applies if

V l .c Vr ∨ V r .c Vl

and the right side is wf

merget({F : V l, F ′ : V ′}unique|open,

{F : V r, F ′′ : V ′′}unique|open) = {F : supc(V l, V r),

F ′ : V ′,

F ′′ : V ′′}openmerget(T1, T2) = ⊥ otherwise

supu(V1, V2) = V2 if V1 .u V2

supu(V1, V2) = V1 if V2 .u V1

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 38:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 148

supc(V1, V2) = V2 if V1 .c V2

supc(V1, V2) = V1 if V2 .c V1

join(Γ1,Γ2) = {(id, joint(Γ1(id),Γ2(id))}

joint(T1, T2) = T1 if T2 . T1

joint(T1, T2) = T2 if T1 . T2

the next case applies if

V l .u Vr ∨ V r .u Vl

and the right side is wf

joint({F : V l, F ′ : V ′}unique, {F : V r, F ′′ : V ′′}unique) = {F : supu(V l, V r),

F ′ : nil(V ′),

F ′′ : nil(V ′′)}uniquejoint(T1, T2) = ⊥ otherwise

filter(F1 ∪ F2, F1) = filter(F2, F1)

filter(F1 ∪ F2, F2) = filter(F1, F2)

filter(F1 ∪ F2, F3) = filter(F1, F3) ∪ filter(F2, F3)

filter(F1, F2) = F1

fopt(P1 t P2, F, i) = P2 if fot(proj(P1, i), F ) = void

fopt(P1 t P2, F, i) = P1 if fot(proj(P2, i), F ) = void

fopt(P1 t P2, F, i) = P1 t P2 otherwise

fopt(P t S, F, i) = fopt(S, F, i) if fot(proj(P, i), F ) = void

fopt(P t S, F, i) = P t fopt(S, F, i) otherwise

fopt(S t P2, F, i) = fopt(S, F, i) if fot(proj(P, i), F ) = void

fopt(S t P, F, i) = fopt(S, F, i) t P otherwise

fopt(S1 t S2, F, i) = fopt(S1, F, i) t fopt(S2, F, i)

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA
Page 39:  · Bibliography [AC96]Martin Abadi and Luca Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1st edition, 1996. 4.2 [ACF+13]Esteban Allende, Oscar

Appendix C. The type system of Typed Lua 149

fot(F1 ∪ F2, F3) = fot(F1, F3) if fot(F2, F3) = void

fot(F1 ∪ F2, F3) = fot(F2, F3) if fot(F1, F3) = void

fot(F1 ∪ F2, F3) = fot(F1, F3) ∪ fot(F2, F3) otherwise

fot(F1, F2) = void if F1 <: F2 and F2 <: F1

fot(F1, F2) = F1 otherwise

fipt(P1 t P2, F, i) = P2 if fit(proj(P1, i), F ) = void

fipt(P1 t P2, F, i) = P1 if fit(proj(P2, i), F ) = void

fipt(P1 t P2, F, i) = P1 t P2 otherwise

fipt(P t S, F, i) = fipt(S, F, i) if fit(proj(P, i), F ) = void

fipt(P t S, F, i) = P t fipt(S, F, i) otherwise

fipt(S t P2, F, i) = fipt(S, F, i) if fit(proj(P, i), F ) = void

fipt(S t P, F, i) = fipt(S, F, i) t P otherwise

fipt(S1 t S2, F, i) = fipt(S1, F, i) t fipt(S2, F, i)

fit(F1 ∪ F2, F3) = fit(F1, F3) if fit(F2, F3) = void

fit(F1 ∪ F2, F3) = fit(F2, F3) if fit(F1, F3) = void

fit(F1 ∪ F2, F3) = fit(F1, F3) ∪ fit(F2, F3) otherwise

fit(F1, F2) = F1 if F1 <: F2 and F2 <: F1

fit(F1, F2) = void otherwise

DBD
PUC-Rio - Certificação Digital Nº 1012679/CA