Why does the Haskell base package only define the IsString class to have a conversion from String to ‘like-string’ value, and not define the inverse transformation, from ‘like-string’ value to String?
The class should be defined as:
class IsString a where
fromString :: String -> a
toString :: a -> String
ref: http://hackage.haskell.org/packages/archive/base/4.4.0.0/doc/html/Data-String.html
The reason is IMHO that
IsString‘s primary purpose is to be used for string literals in Haskell source code (or (E)DSLs — see also Paradise: A two-stage DSL embedded in Haskell) via theOverloadedStringslanguage extension in an analogous way to how other polymorphic literals work (e.g. viafromRationalfor floating point literals orfromIntegerfor integer literals)The term
IsStringmight be a bit misleading, as it suggests that the type-class represents string-like structures, whereas it’s really just to denote types which have a quoted-string-representation in Haskell source code.