How do I mark unreachable code paths?

I have a clause in a case expression that may never be reached. For example, suppose that the pattern is {a: true, b: true} and I know that these flags are mutually exclusive. The right way to handle this situation would be to refactor the type model to use a three way switch enumeration type, but it would require a wide refactoring that I cannot afford.

The solution I would reach for in Haskell is error "Unreachable code path". Is there a similar «undefined» thingie in PureScript? What is the idiomatic way to mark dead case clauses?

One thing I considered is to return a default value. This is not acceptable, because reaching this branch should ring every alarm and never go unnoticed.

1 Like

You could use Partial.Unsafe.unsafeCrashWith.

Depending on context this isn’t necessarily going to be better much louder than using a default value though - if it’s in the browser, the alarm bell will probably go unnoticed in the console unless you happen to be checking for it. :wink:

Thank you, this works for me!

1 Like