Comment on the role of the ghost in Hamlet.
Prior to the ghost's presence and interaction with Hamlet, Hamlet is not concerned with revenge. In fact, he's mostly moping and in a state of hopeless gloom about his father's death and his mother's quick marriage to Claudius. When the ghost finally speaks, to Hamlet, the ghost tells him to take vengeance upon Claudius. This is what sets Hamlet's convoluted plan for revenge in motion.
There has been and continues to be debate amongst critics and readers as to the reality of the ghost. Some say the ghost did actually appear to Horatio, Hamlet, Barnardo, and Marcellus. Others say that the ghost was a hallucination; and although being a hallucination to more than one character is difficult to prove, such critics could argue that these characters were predisposed (perhaps because of a communal openness to the supernatural) to want to see apparitions. Still others, suppose that the ghost was a demon (comparable to the witches in Macbeth) who leads Hamlet on a wild revenge chase.
However, it seems most likely that the ghost did actually appear to Barnardo, Horatio, Marcellus, and Hamlet. So, it is more likely that the ghost was real rather than a hallucination seen by so many different characters. (Note that in III.iv., when Hamlet stabs Polonius, the ghost appears; Hamlet can see him but Gertrude can not. This suggests that the ghost's main purpose has nothing to do with Gertrude, and everything to do with encouraging Hamlet to avenge him by killing Claudius.) The ghost notes that he cannot rest until justice has been served. The further implication from this is that Denmark will not return to its natural state (it is "rotten" according to Marcellus at the end of I.iv.) until justice has been served and the ghost, Old King Hamlet, has been avenged. In Act 1, Scene 5, the ghost says:
I am thy father's spirit,
Doomed for a certain term to walk the night,
And for the day confined to fast in fires
Till the foul crimes done in my days of nature
Are burnt and passed away. (I.v.9-13)
Many critics agree that the ghost is that of Hamlet's murdered father and he's come back to Denmark in order to encourage Hamlet to avenge his death. Therefore, the ghost can not rest until Hamlet avenges him by killing Claudius.
However, other scholars suggest that the ghost is actually a demon who entices Hamlet to seek revenge and thus lead to his own death. This is actually suggested in the play by Hamlet himself.
The spirit that I have seen
May be the devil, and the devil hath power
T'assume a pleasing shape; yea, and perhaps,
Out of my weakness and my melancholy-
As he is very potent with such spirits-
Abuses me to damn me. (II.ii.575-80)
There is also uncertainty as to whether the ghost is real or simply a hallucination, albeit one seen by more than one character (Hamlet, Marcellus, Horatio, and Barnardo). While there is uncertainty about whether or not the ghost was real, the majority consensus is that Shakespeare intended that the audience viewed the ghost to be real, a real manifestation of Hamlet's father's dead soul, having come back to encourage Hamlet to set things right. Whether or not the ghost is real, his is incredibly important because it is he who sets (to Hamlet) the entire revenge plot in motion.
Here is the "reality" of the Ghost. The Ghost stands in stark contrast with Claudius. As much as the Ghost is an image, Claudius is the reality. Or so it seems and that is one aspect of one of the major themes in the play. As the play progresses we get the sense that the Ghost is becoming more real and it is Claudius who begins to look more image than reality.
The next thing we know is that the Ghost is right. Though Hamlet and the others are right to challenge their perceptions, the Ghost's information turns out to be true. Particularly for Hamlet this helps in establishing the Ghost's reality and the reality of its message.
Third, and Shakespeare is very clever to tie this to another major thematic element in the play, the Ghost's image is tied directly to each character's memory of the dead King Hamlet. Notice that I did not say that the Ghost looks like the dead king because there is no such direction in any of the received texts of the play. All the Ghost tells us is that "I am thy father's spirit...' The realities of the play world vary wildly as to how the Ghost is portrayed to any given audience and so to all of us, the audience, the Ghost looks the same. Such is the limitations of the stage. But this reflects directly back to the subtlest aspect of the first theme I mentioned and that is for the characters the whole play is built on perceptions and misperceptions of one another. But I digress. Each character sees the Ghost as they remember him in life. This is why Gertrude cannot see the Ghost. She has completely forgotten her dead husband. And that ties to another thematic element in the play. That is bestial oblivion vs. God-like reason.
The real remaining question is what is the true purpose of the Ghost within the context of the play? I suggest he is one of the three father figures in the play for Hamlet that prompts him to grow up before he is willing. (As I suppose it is with us all.) The two affirmative duties the Ghost charges Hamlet with in one aspect are opposites. One in "remember me" the Ghost is saying use you head. The other in seeking revenge it is saying use your heart. The play makes clear that revenge is not a rational act. The difficulty for Hamlet through the play is governing the two.