Proposal: Add Data.String, containing IsString(fromString), to base

David Roundy droundy at
Tue Jan 30 12:12:27 EST 2007

On Tue, Jan 30, 2007 at 01:54:02PM +0000, Ian Lynagh wrote:
> +-- | Class for string-like datastructures; used by the overloaded string
> +--   extension (-foverloaded-strings in GHC).
> +class IsString a where
> +    fromString :: String -> a
> +
> +instance IsString [Char] where
> +    fromString xs = xs

Wouldn't it make sense to have IsString require an Eq instance?

class Eq a => IsString a where

so that string literals could be used in pattern matching? The
only reason I could see not to do this would be if you wanted to make
something like (Ptr CChar) be an IsString, but that seems pretty crazy to
me.  I guess you could make (ForeignPtr CChar) be an IsString, and that
wouldn't be particularly crazy, but it still seems ugly, and reasonably

I'd rather have the inferred type of

foo "bar" = True


foo :: IsString a => a -> Bool


foo :: (Eq a, IsString a) => a -> Bool

or even worse, to have pattern matching not work as expected with
David Roundy

More information about the Libraries mailing list