The form and style of "When I Heard the Learn'd Astronomer" are representative of almost all of Whitman's poetry. This poem is written in the poet's own particular brand of free verse, without a specific pattern of rhyme or meter. The line lengths vary greatly, and you might notice that in your edition some of the lines appear to be independent. In fact, these are not separate lines – Whitman just couldn't fit the entire line on the page! Thus, the poem consists of eight lines, structured like a short anecdote or even a joke. The first four lines set up the situation, and the last four tell what happened.
Whitman was an innovator when it came to rhythm. His tone might seem rambling to the untrained year, but that would be like saying a Miles Davis trumpet solo is "just a bunch of random notes." Take the beginning of the first four lines. The first two lines have a long, stressed beat on the third syllable: "When I heard" and "When the proofs." Lest he fall into a pattern, he shifts to the long beat to the fourth syllable in the third line: "When I was shown." In the fourth line, he backs the trolley up and creates a long beat on the second syllable using a comma: "When I,". Like a jazz musician, Whitman's free verse uses variations on a theme.