• 6 Posts
  • 1.03K Comments
Joined 1 year ago
cake
Cake day: July 31st, 2023

help-circle



















  • That’s not the point, though. The point is to use a nominal type that asserts an invariant and make it impossible to create an instance of said type which violates the invariant.

    Both validation functions and refinement types put the onus on the caller to ensure they’re not passing invalid data around, but only refinement types can guarantee it. Humans are fallible, and it’s easy to accidentally forget to put a check_if_valid() function somewhere or assume that some function earlier in the call stack did it for you.

    With smart constructors and refinement types, the developer literally can’t pass an unvalidated type downstream by accident.