Advertisement
tinyevil

Untitled

Feb 25th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. class ArrowExpr: public Expr{
  2. public:
  3.  
  4. Expr typecheck(Context& c){
  5. Expr p = paramType.nf(c);
  6. Expr b = bodyType.subst(0, p).nf(c);
  7.  
  8. if ( p is not TypeExpr or b is not TypeExpr ){
  9. throw err;
  10. }
  11.  
  12. int lev = max(((TypeExpr)p).level, ((TypeExpr)b).level);
  13.  
  14. return TypeExpr(lev);
  15. }
  16.  
  17. Expr nf(Context& c){
  18. Expr paramNF = paramType.nf(c);
  19. return ArrowExpr(paramNF, c.withBinding(paramNF, [](Context& c){
  20. return bodyType.nf(c)
  21. });
  22. }
  23.  
  24. Expr subst(int index, Expr e){
  25. return ArrowExpr(paramType.subst(index, e), body.bodyType(index + 1, e));
  26. }
  27.  
  28. bool depends(int index){
  29. return paramType.depends(index) || bodyType.depends(index + 1)
  30. }
  31.  
  32. private:
  33. Expr paramType;
  34. Expr bodyType;
  35. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement