public TypeDeclaration canonicalize(){
  List<Type> sts=getSatisfiedTypes();
  if (sts.isEmpty()) {
    return unit.getAnythingDeclaration();
  }
 else   if (sts.size() == 1) {
    Type st=sts.get(0);
    if (st.isExactlyNothing()) {
      return unit.getNothingDeclaration();
    }
  }
  for (  Type st : sts) {
    if (st.isUnion()) {
      List<Type> caseTypes=st.getCaseTypes();
      List<Type> ulist=new ArrayList<Type>(caseTypes.size());
      for (      Type ct : caseTypes) {
        List<Type> ilist=new ArrayList<Type>(sts.size());
        for (        Type pt : sts) {
          if (pt == st) {
            addToIntersection(ilist,ct,unit);
          }
 else {
            addToIntersection(ilist,pt,unit);
          }
        }
        Type it=canonicalIntersection(ilist,unit);
        addToUnion(ulist,it);
      }
      TypeDeclaration result=new UnionType(unit);
      result.setCaseTypes(ulist);
      return result;
    }
  }
  return this;
}

public TypeDeclaration canonicalize ( ) { List < Type > sts = getSatisfiedTypes ( ) ; if ( sts . isEmpty ( ) ) { return unit . getAnythingDeclaration ( ) ; } else if ( sts . size ( ) == 1 ) { Type st = sts . get ( 0 ) ; if ( st . isExactlyNothing ( ) ) { return unit . getNothingDeclaration ( ) ; } } for ( Type st : sts ) { if ( st . isUnion ( ) ) { List < Type > caseTypes = st . getCaseTypes ( ) ; List < Type > ulist = new ArrayList < Type > ( caseTypes . size ( ) ) ; for ( Type ct : caseTypes ) { List < Type > ilist = new ArrayList < Type > ( sts . size ( ) ) ; for ( Type pt : sts ) { if ( pt == st ) { addToIntersection ( ilist , ct , unit ) ; } else { addToIntersection ( ilist , pt , unit ) ; } } Type it = canonicalIntersection ( ilist , unit ) ; addToUnion ( ulist , it ) ; } TypeDeclaration result = new UnionType ( unit ) ; result . setCaseTypes ( ulist ) ; return result ; } } return this ; }
apply the distributive rule x & ( y | z ) = = x & y | x & z to simplify the intersection to a canonical form with no parens . the result is a union of intersections , instead of an intersection of unions .
