Guest User

Untitled

a guest
Jun 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. class TypeVar {
  2.  
  3. private String name;
  4.  
  5. public TypeVar(String nam){
  6. name = nam;
  7. }
  8.  
  9. public String getName(){
  10. return name;
  11. }
  12.  
  13. }
  14.  
  15.  
  16.  
  17.  
  18.  
  19. class MLType {
  20.  
  21. private TypeVar[][] expression;
  22.  
  23. public MLType(TypeVar[][] array){
  24.     expression = new TypeVar[array.length][];
  25.     for(int i = 0; i < array.length; i++){
  26.         expression[i] = new TypeVar[array[i].length];
  27.         for(int j = 0; j < array[i].length; j++){
  28.             expression[i][j] = array[i][j];
  29.         }
  30.     }
  31. }
  32.  
  33. public boolean findVar(TypeVar a){
  34.     for(int i = 0; i<expression.length; i ++){
  35.         for(int j = 0; i<expression[i].length; j++){
  36.             expression[i][j] == a? return true : continue;
  37.         }
  38.     }
  39.     return false;
  40. }
  41.  
  42. public void mustNotDependOn(TypeVar a) throws ItDoesDependOn{
  43.     findVar a? throw(new ItDoesDependOn) : return;
  44. }
  45.  
  46. public String toString(){
  47.     String rtrn = "";
  48.     for(int i=0; i<expression.length; i++){
  49.         if(expression[i].length == 1){
  50.             rtrn += (expression[i].getName());
  51.         }else{
  52.             rtrn += "("
  53.             for(int j=0; j<expression[i].length; j++){
  54.                 rtrn += (expression[i][j].getName());
  55.                 (j != expression[i].length - 1)? rtrn += "->":rtrn += ")";
  56.             }
  57.         }
  58.         (i != expression.length - 1)?rtrn += "->":continue;
  59.     }
  60. }
  61.  
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. class ItDoesDependOn extends Exception {
  70.  
  71. }
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. import java.util.List;
  79. import java.util.LinkedList;
  80.  
  81. class Types {
  82.  
  83. private static List<TypeVar> types;
  84.  
  85. public static void main(String[] args){
  86. types = new LinkedList<TypeVar>();
  87. }
  88.  
  89. public static void createNewTypeVar(){
  90. types.add(new TypeVar("t" + (types.size()+1)));
  91. }
  92.  
  93. public static TypeVar getType(int n){
  94. return types.get(n-1);
  95. }
  96.  
  97. }
Add Comment
Please, Sign In to add comment