Practical work developed in the context of my Master's Thesis at DCC-FCUP (Faculdade de Ciências da Universidade do Porto) in 2022
- You need to have the Glasgow Haskell Compiler (GHC) installed in your machine. You can download it from https://www.haskell.org/ghc/download.html.
-
LambdaCalculus.hs
: contains the data constructors that define lambda-terms. -
SimpleTypes.hs
: defines simple types and includes the implementation of Robinson's Unification Algorithm (functionunify
) and Milner's Type Inference Algorithm (functionsimpleTypeInf
). -
Rank2IntersectionTypes.hs
: defines rank 2 intersection types and includes the implementation of the algorithm that transforms <=2,1-satisfaction problems into equivalent unification problems (functiontransformSat
) and Trevor Jim's Type Inference Algorithm (functionr2typeInf
). -
LinearTypes.hs
: defines linear types and includes the implementation of our Quantitative Unification Algorithm (functionunifyQ
). -
LinearRank2QuantitativeTypes.hs
: defines linear rank 1 and 2 intersection types and includes the implementation of our Quantitative Type Inference Algorithm (functionquantR2typeInf
). -
Reductions.hs
: defines the functionsmaximal
,normal
andapplicative
that are called by thereduce
function to reduce terms to normal form using the maximal, normal and applicative evaluation strategies, respectively. -
parser.y
: description of the parser to be generated with Happy. -
parser.hs
: parser generated with Happy. -
inputs
: folder with example input files.
In order to use the parser, you first need to compile parser.hs
with ghc -o parser parser.hs
in the terminal, and then you can execute the parser
file generated with the command ./parser
.
The parser accepts isolated lambda-terms and calls to the reduction function reduce
and to the type inference functions simpleTypeInf
, r2typeInf
and quantR2typeInf
, applied to lambda-terms.
-
The allowed type inference functions are
ti0
(callssimpleTypeInf
),ti2
(callsr2typeInf
) andqti2
(callsquantR2typeInf
), which infer the type of terms for simple types, rank 2 intersection types and linear rank 2 intersection types with quantitative information, respectively. They should be used in the following way:ti0 (Term)
,ti2 (Term)
andqti2 (Term) count
, whereTerm
is a lambda-term andcount
is an optional argument that, when passed, makes it not display the environment and type inferred, but only the term and the quantitative measure given by the algorithm. -
The allowed reduction functions are
reduceMax
,reduceNorm
andreduceApp
, which callreduce
to reduce a term to normal form using the maximal, normal and applicative evaluation strategies, respectively. They should be used in the following way:reduceMax (Term) Mode
,reduceNorm (Term) Mode
andreduceApp (Term) Mode
, whereTerm
is a lambda-term andMode
is an optional argument that can be eithersteps
orcount
- when passed,steps
makes it also display all the evaluation steps of the term to normal form, andcount
makes it not display the term's normal form, but only the initial term and the length of the evaluation (number of reduction steps). -
Regarding the format of the lambda-terms, applications correspond to 2 terms separated by a space (
Term Term
) and abstractions to\Var.Term
, whereVar
is an alphanumeric string andTerm
is a lambda-term. Terms can also be written between parentheses, for precedence purposes.
To see some examples of input, including the ones used to obtain the experimental results presented in the Thesis, check the example input files in the folder inputs
.
Author: Fábio Reis