Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I really think that's an useful tutorial for all languages with exceptions ( that's an exceptional event ) and normal control flow ( application error, validation, retry ).

Like that code become really simple, but more expressive than returning an int error code each function. A function can return an error with messages or message+data or message+retrycount etc.

With F# (can be done in other languages obv) it's really easy to have different success/failure return types ( amazing type inference ) without writing too much code or having issues with maintenance ( the compiler does his job for us ).

Like that, it's easy to create simple pure function, easier to test and reason about.



>for all languages with exceptions ( that's an exceptional event )

Unless, like me, you expect the unexpected.

  // if we're still here, guess it worked!

  return retval;
  }


FYI, this "railway" approach is basically the way Promises work.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: