velocity() simply returns the first argument, after doing validity checking based on the second argument.
You probably couldn't reasonably use this everywhere that you would use actual constrained types in a language that has them, but you could probably catch a lot of errors just using them in initializers.
Say you need to represent velocity in a transportation simulation. You could have a function, velocity, that looks like this:
You use it to wrap constrained values. E.g., velocity() simply returns the first argument, after doing validity checking based on the second argument.You probably couldn't reasonably use this everywhere that you would use actual constrained types in a language that has them, but you could probably catch a lot of errors just using them in initializers.