An IsString (NonEmpty Char) instance

Henning Thielemann lemming at
Sat Sep 2 12:53:46 UTC 2017

On Sat, 2 Sep 2017, Artyom wrote:

>   Background
> IsString is a class that is used with the -XOverloadedStrings extension 
> to support string literals of types other than String - for instance, 
> with the IsString Text instance in scope, you can write "foobar" :: Text 
> and it will compile.

String literals are still allowed to be empty. That is,

    "" :: NonEmpty Char

would now be accepted but would be undefined. It's pretty easy for a user 
to make a non-empty literal empty if he does not know the code and he 
would not notice that "" is actually undefined in this context. Thus I 
think the original programmer should make explicit the problem either by 
the ugly ('f' :| "oobar") notation or using a partial function like
(nonEmptyString "foobar").

More information about the Libraries mailing list