An IsString (NonEmpty Char) instance

Artyom yom at
Sat Sep 2 12:59:49 UTC 2017

Yes, but the same is true for `-XOverloadedLists` and the `IsList`
instance of `NonEmpty`, and we have the `IsList NonEmpty` instance anyway.

By the way, it'd be nice to have GHC warn about such cases, the same way
it already warns about integer literals that are guaranteed to overflow:

> 257 :: Word8
<interactive>:3:1: warning: [-Woverflowed-literals]
    Literal 257 is out of the Word8 range 0..255

I can try implementing this along with the libraries patch, but I don't
have any experience with contributing to GHC and it might take some time.

On 09/02/2017 03:53 PM, Henning Thielemann wrote:
> 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