top s =
  if (length (tmp s)) > 0
    then head (tmp s)
    else (stack s) !! ((length (stack s)) - 1 - ((gap s) - 1))
top s =
  if (length (tmp s)) > 0
    then head (tmp s)
    else (stack s) !! ((length (stack s)) - 1 - ((gap s) - 1))
top s =
  if (length (tmp s)) > 0
    then head (tmp s)
    else (stack s) !! ((length (stack s)) - 1 - ((gap s) - 1))