News for hackers. Stuff that matters.
Re:What can’t the internet handle in 2022? Apostrophes by mejutoco on Tuesday October 04, 2022 @10:56AM (#33081292)
This is a good idea I believe. While I agree it would be convenient to have it in the standard library of more languages, it can be implemented in strongly typed languages, using something like Newtype in haskell. In Typescript, for example, it could be:

  type SanitizedString = string
And somewhere you have a function getSanitizedString and if you don't call that the type system will complain.

Same could be done to represent a distance in Km or miles:

  type DistanceKm = number
  type DistanceMiles = number
And then functions can explicitly use any of them or only some (we could define some function multiplying them to allow 2 arguments only if they are the same type).

There are no comments on this comment yet.