''Words, words, words," sighs Hamlet, when Polonius asks what he is reading. He delights in discussion because it enables him to postpone action. But can you imagine him singing?

Although romantic composers venerated Hamlet, they were baffled by its hero, whose verbal ingenuity seemed incompatible with the emotional surrender required by music. Berlioz, in his choral triptych Tristia, produced a mellifluous lament for Ophelia as she drifts downstream singing a ballad, but he marked the funeral march for Hamlet himself sans paroles: battered by the percussion, the chorus lets out a shriek of grief, then lapses into haunted, anxious humming. Tchaikovsky composed an overture for the play and some interludes to be performed between its acts. Music, avoiding the hero's psychological quirks and dramatic perplexities, keeps to the margins. Hamlet once more is excused from the need to sing, while the orchestra sympathises with his mood of morbid regret.

Braver or perhaps more foolhardy, Ambroise Thomas spent six years during the 1860s repackaging Shakespeare's tragedy to make it fit the decorous conventions of French grand opera; his Hamlet reappears in a new production at Covent Garden this month.

In Paris, during the Second Empire, opera was expected to honour political hierarchy and uphold bourgeois propriety, so Thomas and his librettists turned the characters into respectable citizens. Hamlet abandons his antisocial behaviour, forgets his aversion to Claudius's wassailing, and performs a cheery, extroverted drinking song to welcome the players. His sexual morals are tidied up as well: he has given Ophelia an engagement ring, and sings an apologetic aria beside her tomb rather than jumping into the open grave as he does in the play.

The edicts governing a state theatre during the regime of Napoleon III outlawed the crime of lese-majeste. Gertrude in the opera is horrified by Hamlet's accusation of regicide but ignores that of incest, which to her is a lesser charge; she survives to enjoy a benignly superfluous old age as the Queen Mother. The fear of revolution after 1848 made an un-Shakespearean happy ending mandatory. The Ghost intervenes once more to assert his son's divine right to the succession, and Hamlet ascends the throne while a loyal chorus, having instantly shifted its allegiance away from Claudius, cries "Vive notre Roi!"

Perhaps because Thomas's Hamlet is purged of his antic, indecent wit, the opera belongs to Ophelia - and the best reason for resuscitating it is the Covent Garden debut of the zanily brilliant French coloratura soprano Natalie Dessay. Madness exempts Thomas's heroine from the protocols of the court: she escapes to frolic with the peasants. In her last lunatic rhapsody, she dies into nature, elated by its elemental freedom.

Thomas's bowdlerising of the tragedy can seem cowardly, but there is an epilogue in 20th-century music to his pious, censorious view of Hamlet. Shostakovich and Prokofiev both wrote music to accompany performances of the play in Stalinist Russia, and they did so under ideological constraints not unlike those imposed by Napoleon III. A court composer was expected to suppress Hamlet's disrespect for institutional power; the Soviet commissars demanded a ban on what Shostakovich called "reactionary mysticism", which meant that the Ghost could be heard - made audible by a spectral march in Prokofiev's 1938 score, and by a sudden, fearful cataclysm in Shos-takovich's music for Grigori Kozintsev's film - but not seen.

Tragedy, which suggests that the problems of our world are insoluble, struck the Second Empire as improper. In the Soviet Union, it was even more offensively retrograde: hadn't a collectivised society made everyone happy ever after? Prokofiev was ordered to supply an upbeat ending to the play. Fortinbras is accordingly announced by music of indomitable optimism.

Shostakovich composed incidental music for a 1932 production of the play, which treated the tragedy as a decadent, antiquated farce. The courtiers dance a rambunctious cancan, and Hamlet evades his pursuers in what sounds like a chase from a Chaplin comedy. Ophelia's mad songs are treated as bawdy cabaret turns, not pantheistic anthems like those of Thomas's heroine, or spasms of atonal derangement like the settings composed by Richard Strauss in 1919; she seeks solace in booze, and drowns after she drunkenly tumbles into the river.

When Shostakovich returned to the play in 1964 in his score for Kozintsev's film, he made amends for this glib satire. In mute images and blamelessly abstract musical sounds, the tragedy now denounces totalitarianism. Kozintsev's opening scene shows the castle drawbridges being raised to immure the inhabitants in a labyrinth of intrigue, espionage and surveillance. This extermination of privacy is enforced by Shostakovich's thwacking, knouting armoury of brass and his battering timpani: here he composes a musical equivalent of Stalin's Terror. Hamlet's words are replaced by brutal noise. The hero goes on irrelevantly talking, but as in all interpretations, the truth lies in an unspoken, unwritten subtext. Music, after all, can say things that language dare not articulate.

A recording of Ambroise Thomas's Hamlet is available on EMI Classics. The Royal Opera's new production runs from 12-30 May (020 7304 4000)