Skip to content

Commit

Permalink
a explanation about exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
johnazariah committed Dec 11, 2023
1 parent 4c06f88 commit 2c7c8a3
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions _posts/2023-12-12-y-oh-y.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ Let us carefully understand why it works like this: `f error` (aka `fact0`) is a

So when we invoke `fact0` with `0`, the match condition triggers a valid return; but when we invoke it with `1`, the match condition triggers a call to `omega`. In our case, the `omega` passed in is `error`, which ignores whatever argument is passed in and throws an exception instead.

(It's worth pointing out that functional programmers love _total_ functions, and so eschew exceptions because functions which throw don't return a value for all arguments like well-behaved functions do. I'm deliberately throwing an exception here to violently jar us from a state of complacence - to show that something undesirable needs to be dealt with. We'll get rid of this behaviour soon, so just excuse it for now!)

### 3.2 Oh look, a rabbit hole!
Now that we've understood why there's no mystery at all to this behaviour, let's take the next step:

Expand Down

0 comments on commit 2c7c8a3

Please sign in to comment.