String literals
Lennart Augustsson
lennart at augustsson.net
Mon Nov 13 22:44:51 EST 2006
Oh, I'll take booleans too! But those are easier to fudge with the
existing prelude (which I have).
On Nov 13, 2006, at 12:27 , Simon Peyton-Jones wrote:
> In my experience I've seen more requests for overloaded *Boolean*
> literals than strings. In a Fran context, for example.
>
> Simon
>
> | -----Original Message-----
> | From: haskell-prime-bounces at haskell.org [mailto:haskell-prime-
> bounces at haskell.org] 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 haskell.org
> | http://www.haskell.org/mailman/listinfo/haskell-prime
More information about the Haskell-prime
mailing list