Comment by mrkeen

2 days ago

Maybe procedural programmers should take a look instead. I don't see functions.

  a function from a set X to a set Y assigns to each element of X exactly one element of Y.

[https://en.wikipedia.org/wiki/Function_(mathematics)]

Under this strict definition you can’t even throw exceptions!

  • Of course you can: you just have to define it in your type. The output set becomes a union type of the normal output and whatever you want as an exception.

    If you write this as a monad, your get very similar syntax to procedural code.

    • I get what you are saying, but…

      An exception is different to an Either result type. Exceptions short circuit execution and walk up the call tree to the nearest handler. They also have very different optimization in practice (eg in C++)

      1 reply →

  • Then allow partial functions too. Maybe even require them to be tagged as such. (Is that within the capabilities of Zig's programmable type system?)

    I don't mind escape hatches - as long as they're visible/greppable in the source code. You can always write undefined/error/panic/trace directives while you're coding, then come back and remove them later.

    • I would love a language that distinguishes functions (pure mathematical constructs) from procedures (imperative constructs that map in a predictable way to the instruction set).

      This feels like the direction Algebraic Effects might take us.