I'd like my favorite philosopher ever to answer this matter for me in his own words (well, translated from his German):
"...the law and its fulfillment, namely punishment, are directed essentially to the future, not to the past. This distinguishes punishment from revenge, for revenge is motivated by what has happened, and hence by the past as such. All retaliation for wrong by inflicting a pain without any object for the future is revenge, and can have no other purpose than consolation for the suffering one has endured by the sight of the suffering one has caused in another. Such a thing is wickedness and cruelty, and cannot be ethically justified. ...the object of punishment...is deterrence from crime.... Object and purpose for the future distinguish punishment from revenge, and punishment has this object only when it is inflicted in fulfillment of a law. Only in this way does it proclaim itself to be inevitable and infallible for every future case; and thus it obtains for the law the power to deter...."
― Arthur Schopenhauer
"...the law and its fulfillment, namely punishment, are directed essentially to the future, not to the past. This distinguishes punishment from revenge, for revenge is motivated by what has happened, and hence by the past as such. All retaliation for wrong by inflicting a pain without any object for the future is revenge, and can have no other purpose than consolation for the suffering one has endured by the sight of the suffering one has caused in another. Such a thing is wickedness and cruelty, and cannot be ethically justified. ...the object of punishment...is deterrence from crime.... Object and purpose for the future distinguish punishment from revenge, and punishment has this object only when it is inflicted in fulfillment of a law. Only in this way does it proclaim itself to be inevitable and infallible for every future case; and thus it obtains for the law the power to deter...."
― Arthur Schopenhauer