Remix.run Logo
__red__ 2 days ago

Pony is a strongly typed language. If you want your functions to return an Optional Type, define an Optional Type.

For example, the OpenFile API returns you either a valid pony File object, or why it failed (FileEOF, FileBadFileNumber, FileExists, FilePermissionDenied, etc…).

What partial functions do is ensure that all of the error cases are actively addressed by the programmer, so you don't get panics or SEGVs.

ameliaquining 19 hours ago | parent [-]

The problem is, what exactly do you do when your program hits a precondition or invariant violation?

There are basically only two possibilities: abort the process, or jump to a top-level handler that logs the error and returns a 500 response (or whatever the equivalent is, for a long-running program that's not a web server). In neither case is there any interesting decision to be made about how the direct caller should handle the error. In return, whenever you subscript an array or otherwise do anything that has preconditions or invariants, you have to add a question mark to every function that can transitively call it and every call site of same, throughout the codebase. This task requires no intelligence—it can be done algorithmically without error—so why require it?

If you could actually prevent precondition and invariant violations at compile time, that would be quite a different proposition, but Pony can't actually do that (because it requires dependent types) and the intermediate solution they've hit on appears to be the worst of all worlds.

Also, it seems perverse to have a syntax for calling fallible functions and propagating failures up the call stack, but then not allow it to be used for exceptional results, which are the kind of failure that's actually worth propagating up the call stack.

__red__ 15 hours ago | parent [-]

You can do this:

  try
    somearray(outofboundindex)?
    // stuff
  else
    errorlog.write("some message")
    error
  end
Sure you can make it propogate all the way up if you really want, but ugh… what a terrible idea for instrumentation.

Pony doesn't force you to deal with errors a specific way. Pony forces you to make a choice so you can't just ignore it.

ameliaquining 14 hours ago | parent [-]

That code is only allowed in a partial context, right? So if you don't propagate it all the way up the call stack, what do you do instead?