Research shows that appropriate humor can boost learning, productivity and communication—as long as it doesn’t cross the line.