The problem is that there is another very negative element too: Collective vengence. The social desire to see those who offend society made to suffer. Worse, this can be counterproductive to the rehabilitation role: Programs aimed at educating prisoners are widely seen as 'soft on crime,' while there is widespread support for any policy that increases the difficulty released prisoners face in finding housing and employment.
As a Norwegian, that seems insane to me. We have some of the nicest prisons in the world, and inmates are given the opportunity to get an education. We also have one of the lowest recidivism rates in the world at around 20%. The authorities have a stated goal to reduce recidivism by providing opportunities for reform in prison. This includes hard criminals like perpetrators of gang-related killings, robbers who have shown willingness to kill police officers in shoot-outs, and drug related crimes, which are among the worst when it comes to recidivism. Although some employers and neighbourhoods frowns on ex-convicts, they generally have lots of opportunities to reinstate themselves in society. You're less likely to be considered for a trusted position, but it even happens that former convicts get one of those with the employers full knowledge of their past (depending on the nature of their crimes and the position).
The punishment constitutes loss of freedom and communication rights - nothing more. The conditions in prisons are good (Halden Prison and Bastøy Prison are some of the "best", but the penal philosophy is the same for all of them), because they're not supposed to make you suffer physically or psychiologically. The political right wing (which even many US Democrats would probably still call liberal bleeding-heart commies) occasionally bleats about reforms to make punishment harsher, but nobody is really serious about it, since the existing system just works too well at turning criminals into productive members of society.
Of course there are a few wackos, like Anders Behring Breivik, for which the regular system doesn't work well. For the likes of him we have 'indefinite detention', our strongest punishment, which is something like life _with_ the possibility of parole. It is still very probable that he'll spend his entire life in prison since an absolute requirement for release is that he's deemed safe by psychologists and other professionals, which doesn't seem likely to happen based on his currently reported statements and behaviour.