When designing a programming language API what are the advantages and disadvantages of:
Like in: Haskell, Erlang, C
Like in: Java, C#, Lisp, JavaScript, ...
Reasons to have them be the same type:
Reasons to have them be different:
can enforce invariants through type. If your strings are stored in an encoding where not every possible bit pattern is valid, like UTF8, then if String is not its own type, then it will be possible to have invalid strings.
can eliminate multiple copies of the same string. There is a technique called “interning” where only one copy of each distinct value of a type used in the program, is in memory at once. This is commonly done automatically for strings by the language, including by the languages with separate string types you mentioned, (at least for some implementations of Lisp). Doing so for strings has the nice effect of making string comparisons, including string keys in hash tables more efficient. You can do the comparison on the known-unique pointer instead of the string value.