A similar thing can be achieved in Haskell, with the Typeable typeclass. The Scrap Your Boilerplate also fixes problems like this.
There has to be some use for dynamic typing when even Haskell (ghc) adds support for it, I guess.