Enable to define type

I really like this idea! cool hack. And I wanna enable user to define type.

But this PR is just kind of refactoring. I'm not sure the best interface to define type so far.