A new algorithm for compiling pattern matching is presented. Different from the traditional traversal-based approaches, it can represent a sequence of patterns as an integer by an encoding method and translate equations into case-expressions. The algorithm is simple to implement, and efficient for a kind of patterns, i.e. simple and dense patterns. This method can be complementary to traditional approaches.