3 ms·
Type of a string is `string`, the fact that it's internally a `seq[char]` is just an implementation detail. > So how could it violate type safety by treating i
by archargelod 2y ago
Type of a string is `string`, the fact that it's internally a `seq[char]` is just an implementation detail.
> So how could it violate type safety by treating it as such?
By not allowing you to treat a type as a type it's implemented with, Nim could prevent some logical errors. Here's a good example of such logical error from Wikipedia:
> For instance, inches and millimeters may both be stored as integers, but should not be substituted for each other or added.
Or example with strings: Nim has `Path` type that's implemented as `distinct string`. You can't mix and match Path and string, unless you explicitly convert their types:
import std/paths
let prefix = Path("/usr")
let bins = "bin"
echo prefix / bins # not allowed
echo prefix / Path(bins) # allowed
This makes it a bit harder to do something bad or stupid by accident.