110 likes | 204 Views
Integrated Crono. Crono with Combinators and Type Inferencing. Initial Modifications. Starting with c rono_typeInferencing , the following changes are made for integrating crono_combinator . Parser.jj Added grammar for recognozing Combinators. CronoFunctions.java
E N D
Integrated Crono Crono with Combinators and Type Inferencing
Initial Modifications • Starting with crono_typeInferencing, the following changes are made for integrating crono_combinator. • Parser.jj • Added grammar for recognozing Combinators. • CronoFunctions.java • Added functions COND and PRED. • Modified the run() method for ADD, SUB, MULT, DIV • Cons.java • Added an append() method • Environment.java • Interpreter.java • Added a run() method for Combinators • Changed eval() method to deal with Combinators also.
Initial Modifications • In addition to the above changes, the following classes from crono_combinator are also added. • CombSymbol.java • CronoString.java • CronoDouble.java • CombinatorFunction.java
Type Inferencing for Combinators The way Type Inferencing works is • A CronoConstraintCreator object is created. • The infer() method of this object is called with the reguired function as the argument. • The infer() method creates a list of type constraints. • Then, the unify() method of the CronoConstraintCreator is called, which then applies the unification algorithm over the constraints obtained so that when type() is called the next time, the correct type of the function is retured.
Type Inferencing for Combinators • Since the unify() method merely processes the type constraints given to it, in order to provide Type Inferencing for Combinators, we do not need to modify this method. • We need to modify the method of creating constraints so that type constraints are created for Combinators also. • Since constraints are created in the infer() method, we only need to change this method.
Type Inferencing for Combinators • The original infer() method checks for instances of Symbol, CronoNumber, and Cons • Inside the Cons section, it again checks for instances of Symbolto create constraints for non-combinator functions. • In order to create type constraints for Combinators we need to check for instances of CombSymbol under the Cons section.
Type Inferencing for Combinators • The structure of the body of the if-statement for the CombSymbol is very similar to that of Symbol. • In this body, each of the five combinators, namely <S>, <K>, <B>, <C>, <Y>, is processed in a separate case based on their definitions. [see next slide for definitions]
Type Inferencing for Combinators • For any instance, the infer() method calls the constraint() method of that instance • This method defines how the types of the different parts of the concerned function are related. • Hence, we need to define this method for the newly added instance, CombSymbol. • We also need to define this method for the newly added functions COND and PRED in the CronoFunctions.java
Type Inferencing for Combinators • Finally, inside the body of the if-statement for Symbol under the Cons section, we need to deal with the function COND as a separate case because this function can be defined differently in different cases. • For example, not all required arguments are given in some cases. • After making the above changes, the type of the combinator functions should be generated correctly.
Errors in Evaluation: • At this point the evaluation of the function gives incorrect results. • The reason for this is • When requesting for the type of function, the Cons object defining the function is passed to the infer() method. • Inside the infer() method we manipulate the contents of this Cons object several times. • Since the contents of the Cons object are pointers to objects like Symbol, CombSymbol etc, changing these contents also changes the original function.
Solution: • Make a deep copy of the Cons object, and pass that copy to the infer() method. • Now, the crono_combinators is completely integrated into crono_typeInferencing