11 ms·
But a string is a seq of chars in nim. I ran some type checking code that showed me that that is what it is. So how could it violate type safety by treating it
by big-green-man 2y ago
But a string is a seq of chars in nim. I ran some type checking code that showed me that that is what it is. So how could it violate type safety by treating it as such?
- archargelod 2y agoType 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.