上QQ阅读APP看书,第一时间看更新
Pattern matching
Pattern matching is often used with ADTs. It makes the code much clearer and more readable as well as easier to extend in comparison to using the if…else statements when trying to do something with ADTs based on their values. As you could imagine, these statements can get quite cumbersome in some cases, especially when there are many different possible values for a certain data type. In some cases, pattern matching can be used the same way as enums and the switch statement is used in Java.