-- Construct a new output stack by applying an operator,
-- a symbol, or a list to the top of the output stack.
apply :: Token a => Tree a -> [[SExpr a]] -> [[SExpr a]]
apply (Part y) (os:oss) | end y =
  if length l /= nargs
  then error "can't happen" -- holes are always filled by one expression
  else (operator (original y) (reverse l) : r) : oss
  where nargs = arity y
        (l,r) = splitAt nargs os
apply :: Token a => Tree a -> [[SExpr a]] -> [[SExpr a]]
apply (Part y) (os:oss) | end y =
  if length l /= nargs
  then error "can't happen" -- holes are always filled by one expression
  else (operator (original y) (reverse l) : r) : oss
  where nargs = arity y
        (l,r) = splitAt nargs os
apply (Part y) (os:oss) | end y =
  if length l /= nargs
  then error "can't happen" -- holes are always filled by one expression
  else (operator (original y) (reverse l) : r) : oss
  where nargs = arity y
        (l,r) = splitAt nargs os