In a visit expression, can the default be labeled like the cases?

StackOverflow https://stackoverflow.com/questions/16544384

  •  29-05-2022
  •  | 
  •  

سؤال

Example:

visit(Sometree)
{
    case a:someNodeA(_,_): HandleNodeA(a);
    default:               Handle(???);
}

So i want to handle all the other cases by using default, how can I do this?

هل كانت مفيدة؟

المحلول

visit does not support default because it needs something specific to bind while visiting. Instead you can write a pattern that matches truly everything. For example:

visit(sometree) {
   case node x : handleAllTreeLikeThings(x);
   case str y(value x, value y) : handleAllBinaryTrees(y, x, y);
   case value x : handleAllValuesWhatsoever(x);
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top