Generalize IsString

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Generalize IsString

Dannyu NDos
As we already have IsList, shouldn't we just do this?

class (IsList l, Item l ~ Char) => IsString l

instance (a ~ Char) => IsString [a]
instance (a ~ Char) => IsString (NonEmpty a)
instance (a ~ Char) => IsString (ZipList a)

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Generalize IsString

chessai .
This would require desugaring string literals using `fromListN`, which would require GHC effort.

Also, consider ByteString. Is `Item ByteString` `Word8` or `Char`?

Additionally, I'm not convinced this coupling really buys us much. You could always define `fromString = fromList`. 

On Fri, Jun 5, 2020, 11:12 PM Dannyu NDos <[hidden email]> wrote:
As we already have IsList, shouldn't we just do this?

class (IsList l, Item l ~ Char) => IsString l

instance (a ~ Char) => IsString [a]
instance (a ~ Char) => IsString (NonEmpty a)
instance (a ~ Char) => IsString (ZipList a)
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Generalize IsString

Zemyla
There are some things which I've seen with IsString instances which can't have toList applied to them, like parsers.

On Sat, Jun 6, 2020, 01:25 chessai . <[hidden email]> wrote:
This would require desugaring string literals using `fromListN`, which would require GHC effort.

Also, consider ByteString. Is `Item ByteString` `Word8` or `Char`?

Additionally, I'm not convinced this coupling really buys us much. You could always define `fromString = fromList`. 

On Fri, Jun 5, 2020, 11:12 PM Dannyu NDos <[hidden email]> wrote:
As we already have IsList, shouldn't we just do this?

class (IsList l, Item l ~ Char) => IsString l

instance (a ~ Char) => IsString [a]
instance (a ~ Char) => IsString (NonEmpty a)
instance (a ~ Char) => IsString (ZipList a)
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Generalize IsString

chessai .
Ah, good point Zemyla. Also HtmlT, from Lucid.

On Sat, Jun 6, 2020, 4:12 AM Zemyla <[hidden email]> wrote:
There are some things which I've seen with IsString instances which can't have toList applied to them, like parsers.

On Sat, Jun 6, 2020, 01:25 chessai . <[hidden email]> wrote:
This would require desugaring string literals using `fromListN`, which would require GHC effort.

Also, consider ByteString. Is `Item ByteString` `Word8` or `Char`?

Additionally, I'm not convinced this coupling really buys us much. You could always define `fromString = fromList`. 

On Fri, Jun 5, 2020, 11:12 PM Dannyu NDos <[hidden email]> wrote:
As we already have IsList, shouldn't we just do this?

class (IsList l, Item l ~ Char) => IsString l

instance (a ~ Char) => IsString [a]
instance (a ~ Char) => IsString (NonEmpty a)
instance (a ~ Char) => IsString (ZipList a)
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Generalize IsString

Mario
In reply to this post by Dannyu NDos
On 2020-06-06 2:11 a.m., Dannyu NDos wrote:
> As we already have IsList, shouldn't we just do this?
>
> class(IsListl, Iteml~Char) => IsStringl
> instance(a~Char) => IsString[a]
> instance(a~Char) => IsString(NonEmptya)
> instance(a~Char) => IsString(ZipLista)
>

That's not a generalization, it's a restriction. It would, for example,
exclude both ByteString (whose IsString instance is admittedly broken)
and ByteStringUTF8 (whose isn't).


_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries