String literals

Simon Peyton-Jones simonpj at
Mon Nov 13 12:27:08 EST 2006

In my experience I've seen more requests for overloaded *Boolean* literals than strings.  In a Fran context, for example.


| -----Original Message-----
| From: haskell-prime-bounces at [mailto:haskell-prime-bounces at] On Behalf Of
| Lennart Augustsson
| Sent: 11 November 2006 03:49
| To: Haskell Prime
| Subject: String literals
| I think it's time that string literals got overloaded just like
| numeric literals.  There are several reasons for this.  One reason is
| the new fast string libraries.  They are great, but string literals
| don't work; you need to pack them first.  Another reason is the
| increasing use of Haskell for DSELs.  In a DSEL you might want string
| literals to have a different type than the ordinary String.
| I have not implemented anything yet, but I would like to see
| something along the lines of the following:
| class IsString s where
|      fromString :: String -> s
| instance IsString String where
|      fromString = id
| The instance declaration is not allowed in Haskell-98, but it can be
| rewritten as
| class IsChar c where  -- Make this class local to it's defining module
|      fromChar :: Char -> c
| instance IsChar Char where
|      fromChar = id
| instance (IsChar c) => IsString [c] where
|      fromString = map fromChar
| And, like with numeric literals, any string literal will then have an
| implicit fromString insert to make the right conversion.
| My guess is that the defaulting mechanism needs to be extended to
| default to the String type as well, or we'll get some ambiguous
| expressions.
| Any thoughts?
|         -- Lennart
| _______________________________________________
| Haskell-prime mailing list
| Haskell-prime at

More information about the Haskell-prime mailing list