In Functional Programming, is it considered a bad practice to have incomplete pattern matchings

前端 未结 7 1352
梦毁少年i
梦毁少年i 2020-12-09 02:12

Is it generally considered a bad practice to use non-exhaustive pattern machings in functional languages like Haskell or F#, which means that the cases specified don\'t cove

7条回答
  •  时光取名叫无心
    2020-12-09 02:32

    Explicit is better than implicit (borrowed from the Zen of Python ;))

    It's exactly the same as in a C switch over an enum... It's better to write all the cases (with a fall through) rather than just putting a default, because the compiler will tell you if you add new elements to the enumeration and you forgot to handle them.

提交回复
热议问题