I know that Elm's Debug module has the `crash` method, which can be used to "stub" non-implemented patterns in a similar way to Haskell's `undefined`.
fn : Bool -> String
fn x =
case x of
True -> "It's True!"
False -> crash "Undefined!"
fn True |> show => "It's True"
fn False |> show => (raises error "Undefined!")
Cool! That works the way I want it to. It compiles, but raises an error in Javascript if the "crash" is ever invoked.
To make this sort of pattern a bit more concise, I wanted to implement the `undefined` method in a simple way.
undefined : a
undefined = crash "Undefined!"
However, when I use this function defined in the above example the Javascript seems to evaluate the crash for some reason.
fn : Bool -> String
fn x =
case x of
True -> "It's True!"
False -> undefined
fn True |> show => (raises error "Undefined!")
Strangely, even defining the function `undefined` but not evaluating it anywhere in the main sequence causes the Javascript to crash after the compiler gives it an OK.
Can anyone shed some light on this situation? I understand that Elm cannot lazily evaluate code in the same way Haskell does because it compiles to Javascript, but it seems strange that simply defining the `undefined` function without invoking it causes an error. What am I not understanding about the way Elm evaluates functions and/or compiles to Javascript?