Esempio n. 1
0
 /*
  * (non-Javadoc)
  *
  * @see jaskell.compiler.JaskellVisitor#visit(jaskell.compiler.core.Alternative)
  */
 public Object visit(Alternative a) {
   Iterator it = a.getChoices();
   while (it.hasNext()) {
     Map.Entry entry = (Map.Entry) it.next();
     Expression body = (Expression) entry.getValue();
     entry.setValue(body.visit(this));
   }
   return a;
 }
Esempio n. 2
0
  /** @see jaskell.compiler.JaskellVisitor#visit(Alternative) */
  public Object visit(Alternative a) {
    try {
      Type tex = (Type) a.getExpression().visit(this);
      log.finer("In alternative, type of expression " + a.getExpression() + " is " + tex);

      /* set type of bound variable */
      LocalBinding lb = a.getBinding();
      if (lb != null) lb.setType(tex);
      /* visit type of alternatives */
      Iterator it = a.getChoices();
      Type ptype = tex;
      Type btype = null;
      while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        /* checkt type of pattern */
        Type pt = (Type) ((Pattern) entry.getKey()).visit(this);
        if (ptype == null) ptype = pt;
        else ptype = tu.unify(pt, ptype, typeVariablesMap);
        log.finer("In alternative, unifying pattern type " + pt + " to " + ptype);
        Expression expr = (Expression) entry.getValue();
        /* check type of body */
        Type bt = (Type) expr.visit(this);
        //                      /* apply substitution with type variables from pattern */
        //                      TypeSubstitution ts = new TypeSubstitution(typeVariablesMap);
        //                      expr.visit(ts);
        if (btype == null) btype = bt;
        else btype = tu.unify(bt, btype, typeVariablesMap);
        log.finer("In alternative, unifying body type " + bt + " to " + btype);
      }
      /* visit default choice */
      Type deft = (Type) a.getWildcard().visit(this);
      a.setType(btype);
      return btype;
    } catch (TypeError te) {
      if (te.getLineCol() == null) te.setLineCol(a.getTag("source"));
      throw te;
    }
  }