This issue is the tip of the iceberg when you look up recent research papers - we have a pandemic of Vitamin D Deficiency on our hands, and the implications that several decades hysterically denying our evolutionary history allow; there is a price to be paid for this kind of scientific misunderstanding. In brief, the UV Energy (UVB and UVA wavelengths) from the sun has four primary effects (I won't yet mention the many other benefits that are currently being realized):
1. UVB is the only really effective way for us to synthesize 25(OH)D - this is a profoundly, nay critical, good thing, and is a key agent to protect against cancer.
2. UVB causes erythema (the sunburn reaction) - this is a very important good thing, as it tells us we've over-egged the pudding, and hopefully we as a result desist, and don't do it again.
3. UVB causes the tanning reaction, to protect our physiology from excessive UVB, and more importantly, protect our cells Nuclei from high-energy UVA wavelengths - again, a profoundly good thing. (For decades, sunblocks have only stopped UVB energy, and under the false sense of security that the resulting lack of burn-reaction afforded, allowed us to cook our DNA in UVA, which sniggered at the sunscreen as it sailed on through to our deeper layers and blood vessels. More recent (multi-spectrum) sunscreens stop the UVA. Mostly. I think.
4. Primarily via burning/overexposure without appropriate tanning buildup, UVA/UVB promotes a level of skin cancer, mainly basal/squamous cell carcinomas, which are very treatable/curable when not left too long to develop. Note that it's the UVA primarily that is suspected of being the bad actor in promoting Melanoma, a more nasty beast indeed.
So, we have a classic engineering tradeoff here. Sun: Lots of good, some bad also - what's the optimum though? Well, you'll have to wait for my Vitamin D seminar, but here's a little clue in the interim:
Avoidance of sun exposure is a risk factor for all-cause mortality: results from the Melanoma in Southern Sweden cohort. http://www.ncbi.nlm.nih.gov/pubmed/24697969