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

前端 未结 7 1371
梦毁少年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条回答
  •  萌比男神i
    2020-12-09 02:31

    Non-exhaustive pattern machings are idiomatic in Haskell but extremely bad style in F# (and OCaml, Standard ML etc.).

    Exhaustiveness checking is a very valuable way to catch errors at compile time in strict languages like F# but lazy languages like Haskell often use infinite lazy lists where the empty list cannot arise so they (historically) chose brevity over statically-checked correctness.

提交回复
热议问题