String literals
Lennart Augustsson
lennart at augustsson.net
Mon Nov 13 08:22:34 EST 2006
To follow up on my own post. I implemented the overloaded strings
last night and it seems to work pretty well. I've not done anything
about defaulting yet. I don't know how much of a problem this will
be in practice.
On Nov 10, 2006, at 22:49 , Lennart Augustsson wrote:
> 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