String != [Char]
Thomas Schilling
nominolo at googlemail.com
Mon Mar 19 16:45:28 CET 2012
On 18 March 2012 19:29, ARJANEN Loïc Jean David <arjanen.loic at gmail.com> wrote:
> Good point, but rather than specifying in the standard that the new string
> type should be the Text datatype, maybe the new definition should be that
> String is a newtype with suitable operations defined on it, and perhaps a
> typeclass to convert to and from this newtype. The reason of my remark is
> although most implementations compile to native code, an implementation
> compiling to, for example, JavaScript might wish to use JavaScript's string
> type rather than forcing its users to have a native library installed.
I agree that the language standard should not prescribe the
implementation of a Text datatype. It should instead require an
abstract data type (which may just be a newtype wrapper for [Char] in
some implementations) and a (minimal) set of operations on it.
Regarding the type class for converting to and from that type, there
is a perhaps more complicated question: The current fromString method
uses String as the source type which causes unnecessary overhead. This
is unfortunate since GHC's built-in mechanism actually uses
unpackCString[Utf8]# which constructs the inefficient String
representation from a compact memory representation. I think it would
be best if the new fromString/fromText class allowed an efficient
mechanism like that. unpackCString# has type Addr# -> [Char] which is
obviously GHC-specific.
--
Push the envelope. Watch it bend.
More information about the Haskell-prime
mailing list