1 / 11

Integrated Crono

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

zeshawn
Télécharger la présentation

Integrated Crono

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Integrated Crono Crono with Combinators and Type Inferencing

  2. 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.

  3. 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

  4. 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.

  5. 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.

  6. 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.

  7. 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]

  8. 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

  9. 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.

  10. 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.

  11. 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

More Related