String != [Char]

Tillmann Rendel rendel at informatik.uni-marburg.de
Tue Mar 20 16:29:27 CET 2012


Hi,

Thomas Schilling wrote:
> 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.

Is this still a problem if String would be replaced by an 
implementation-dependend newtype? Presumably, GHC would use a more 
efficient representation behind the newtype, so the following would be 
efficient in practice (or not?)

   newtype String
     = ...

   class IsString a where
     fromString :: String -> a

The standard could even prescribe that an instance for [Char] exists:

   explode :: String -> [Char]
   explode = ...

   instance IsString [Char] where
     fromString = explode

Tillmann



More information about the Haskell-prime mailing list