Carrots contain beta-Carotene (bet you can't guess the etymology.) Beta-Carotene gets metabolized into various forms of vitamin A, including retinal, which is necessary for eye health.
So, it's not that carrots can help you see in the dark; it's more that some eye diseases (which have initial symptoms including diminished night vision) can be prevented by eating carrots, just like some gum diseases can be prevented by eating oranges.