ANNOUNCE: vector-bytestring-0.0.0.0

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
59 messages Options
123
Reply | Threaded
Open this post in threaded view
|

ANNOUNCE: vector-bytestring-0.0.0.0

Bas van Dijk-2
  All your ByteString are belong to us...

Hello,

I'm pleased to announce the beta release of vector-bytestring. This
library provides the type ByteString which is defined as a type
synonym for a storable Vector of Word8s (from the vector package):

type ByteString = Data.Vector.Storable.Vector Word8

It exports the same API as the bytestring package except that the
module names are prefixed with: Data.Vector.Storable.ByteString
instead of Data.ByteString.

The very ambitious goal of this package is that it will eventually
replace our beloved bytestring package. By basing this package on
vector, we can benefit from all the optimizations (like
stream-fusion!) in that library. We will also have just a single
library to test, debug and optimize.


TEST-SUITE

I ported the bytestring test-suite to vector-bytestring. You can run it using:

$ cabal configure --enable-tests; cabal build; cabal test

All 54800 tests pass! Only one property doesn't hold:

prop_show :: ByteString -> Bool
prop_show x = show x == show (unpack x)

This is because I don't provide a custom Show instance for ByteStrings
but use the one from Vector which shows a vector like "fromList
[1,2,3]" instead as "\SOH\STX\ETX" like bytestring does. Hopefully
this is not a problem in practice.


BENCHMARKS

I added a criterion based benchmark-suite to vector-bytestring. It
consists of over 600 benchmarks that cover almost every function in
the library. Also included are benchmarks which benchmark the fusion
capabilities of the library. Run it using:

$ cabal configure -fbenchmark; cabal build;
$ dist/build/bench/bench --help

Unfortunately, bytestring still out performs us in lots of benchmarks.
I believe the primary cause of this is that most functions are
implemented using stream-fusion. This is highly efficient if you use a
composition of these functions because they will all fuse into one
single efficient loop. However if your program uses only a single
function, the stream based implementation is often less efficient than
an implementation that works directly on a mutable vector (like most
functions in bytestring). So what we want is to use stream-fusion
where possible but use mutable vectors when our program doesn't fuse.
Fortunately, Roman Leshchinskiy (author of vector) has an idea how to
do this: http://trac.haskell.org/vector/ticket/60

Because we don't beat bytestring in all cases yet you should consider
this a beta-release and not use it in production code.


INSTALLING

$ cabal install vector-bytestring


API DOCS

http://hackage.haskell.org/package/vector-bytestring-0.0.0.0


DEVELOPING

$ git clone https://github.com/basvandijk/vector-bytestring


Regards,

Bas

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: ANNOUNCE: vector-bytestring-0.0.0.0

Christian Maeder-2
Am 12.10.2011 16:02, schrieb Bas van Dijk:

>    All your ByteString are belong to us...
>
> Hello,
>
> I'm pleased to announce the beta release of vector-bytestring. This
> library provides the type ByteString which is defined as a type
> synonym for a storable Vector of Word8s (from the vector package):
>
> type ByteString = Data.Vector.Storable.Vector Word8
>
> It exports the same API as the bytestring package except that the
> module names are prefixed with: Data.Vector.Storable.ByteString
> instead of Data.ByteString.
>
> The very ambitious goal of this package is that it will eventually
> replace our beloved bytestring package. By basing this package on
> vector, we can benefit from all the optimizations (like
> stream-fusion!) in that library. We will also have just a single
> library to test, debug and optimize.
>
>
> TEST-SUITE
>
> I ported the bytestring test-suite to vector-bytestring. You can run it using:
>
> $ cabal configure --enable-tests; cabal build; cabal test
>
> All 54800 tests pass! Only one property doesn't hold:
>
> prop_show :: ByteString ->  Bool
> prop_show x = show x == show (unpack x)
>
> This is because I don't provide a custom Show instance for ByteStrings
> but use the one from Vector which shows a vector like "fromList
> [1,2,3]" instead as "\SOH\STX\ETX" like bytestring does. Hopefully
> this is not a problem in practice.

All derived Show instances for data types using your ByteString will be
different, too.

Would it not be simple to use a newtype for ByteString (rather than a
synonym)?

Cheers Christian

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: ANNOUNCE: vector-bytestring-0.0.0.0

Bas van Dijk-2
On 14 October 2011 12:58, Christian Maeder <[hidden email]> wrote:
> Would it not be simple to use a newtype for ByteString (rather than a
> synonym)?

My "vision" for the future of bytestring and vector-bytestring is that
they will be replaced by vector directly. This way users don't have to
think about choosing between bytestring and vector and can go to
vector directly to work with Word8 vectors or interface with foreign
libraries.

This would mean moving some (bytestring only) functions from
vector-bytestring to vector like mapAccumL/R, create, createAndTrim,
etc. and generalizing them from Word8s to any Storable.

So in my vision there's no ByteString type anymore, just Vectors. The
vector-bytestring package is meant to make the transition smoother.

If there's need for a specific Show instance for Vectors of Word8s we
can always add one directly to vector. (Roman, what are your thoughts
on this?)

Bas

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: ANNOUNCE: vector-bytestring-0.0.0.0

Ivan Lazar Miljenovic
On 14 October 2011 22:37, Bas van Dijk <[hidden email]> wrote:
> On 14 October 2011 12:58, Christian Maeder <[hidden email]> wrote:
>> Would it not be simple to use a newtype for ByteString (rather than a
>> synonym)?
>
> If there's need for a specific Show instance for Vectors of Word8s we
> can always add one directly to vector. (Roman, what are your thoughts
> on this?)

I suppose you could add a newtype wrapper, but it _would_ require
duplicating the API to do so.

Though I would argue that unless you're trying to actually use for
Show/Read for serialisation, does it really matter what the Show/Read
instances for Bytestring are?

--
Ivan Lazar Miljenovic
[hidden email]
IvanMiljenovic.wordpress.com

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: ANNOUNCE: vector-bytestring-0.0.0.0

Max Rabkin-2
On Fri, Oct 14, 2011 at 13:45, Ivan Lazar Miljenovic
<[hidden email]> wrote:
> Though I would argue that unless you're trying to actually use for
> Show/Read for serialisation, does it really matter what the Show/Read
> instances for Bytestring are?

Convenient debugging and REPL interaction certainly matter!

--Max

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: ANNOUNCE: vector-bytestring-0.0.0.0

Ertugrul Söylemez
Max Rabkin <[hidden email]> wrote:

> > Though I would argue that unless you're trying to actually use for
> > Show/Read for serialisation, does it really matter what the
> > Show/Read instances for Bytestring are?
>
> Convenient debugging and REPL interaction certainly matter!

On the other hand, having a separate Show instance for Vector Word8
would require either writing all Show instances explicitly or keeping
two separate packages.  I would prefer to have the two packages merged
into one.

But since I find a useful Show instance for ByteString useful, too, I
would go with the first variant of providing a few default instances
instead of a generic Show a => Show (Vector a) instance.  That way you
can write nicer instances for some other element types, too.  For
example I can imagine how a much nicer Vector Bool instance would look
like:

    fromBoolString "1.1..111..1"


Greets,
Ertugrul


--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/



_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: [Haskell] ANNOUNCE: vector-bytestring-0.0.0.0

Bas van Dijk-2
In reply to this post by Bas van Dijk-2
On 14 October 2011 14:01, Ertugrul Soeylemez <[hidden email]> wrote:
> Is there any particular reason to prefer storable vectors instead of
> unboxed vectors?  The element type is fixed to Word8 anyway.

To be able to safely interface with foreign libraries.

Note that unboxed vectors are represented as ByteArray#s. These are
"unpinned" which means that the GC can freely move them through the
heap to defragment your memory. If a foreign library had a pointer to
an unboxed vector and the GC would move the memory to some place else,
your program could crash. Storable vectors use a ForeignPtr instead
which (according how you allocated it) points to "pinned" memory.

You might like to follow the just created:

http://hackage.haskell.org/trac/ghc/ticket/5556

which proposes the pin# and unpin# primitives for dynamically pinning
and unpinning ByteArray#s. This way, as pumpkin explains it, you don't
have to decide up front whether you want to suffer from memory
fragmentation or to support foreign bindings.

It would be really nice if that could be implemented!

Bas

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: ANNOUNCE: vector-bytestring-0.0.0.0

Bas van Dijk-2
In reply to this post by Bas van Dijk-2
On 14 October 2011 13:37, Bas van Dijk <[hidden email]> wrote:
> If there's need for a specific Show instance for Vectors of Word8s we
> can always add one directly to vector. (Roman, what are your thoughts
> on this?)

Ok I have proposed and implemented this for vector:

http://trac.haskell.org/vector/ticket/64

Bas

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: ANNOUNCE: vector-bytestring-0.0.0.0

Roman Leshchinskiy
In reply to this post by Bas van Dijk-2
On 14/10/2011, at 12:37, Bas van Dijk wrote:

> If there's need for a specific Show instance for Vectors of Word8s we
> can always add one directly to vector. (Roman, what are your thoughts
> on this?)

Personally, I think that ByteString and especially Vector Word8 aren't strings and shouldn't be treated as such. But I wouldn't be strongly against showing them as strings. However, I *am* strongly against using UndecidableInstances in vector and I don't see how to implement this without using them.

Roman



_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: ANNOUNCE: vector-bytestring-0.0.0.0

Roman Leshchinskiy

On 15/10/2011, at 12:26, Roman Leshchinskiy wrote:

> On 14/10/2011, at 12:37, Bas van Dijk wrote:
>
>> If there's need for a specific Show instance for Vectors of Word8s we
>> can always add one directly to vector. (Roman, what are your thoughts
>> on this?)
>
> Personally, I think that ByteString and especially Vector Word8 aren't strings and shouldn't be treated as such. But I wouldn't be strongly against showing them as strings. However, I *am* strongly against using UndecidableInstances in vector and I don't see how to implement this without using them.

I meant OverlappingInstances, of course. To clarify, I would still consider it if everybody thinks it's a really good idea.

Roman



_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: ANNOUNCE: vector-bytestring-0.0.0.0

Bas van Dijk-2
On 15 October 2011 13:34, Roman Leshchinskiy <[hidden email]> wrote:

>
> On 15/10/2011, at 12:26, Roman Leshchinskiy wrote:
>
>> On 14/10/2011, at 12:37, Bas van Dijk wrote:
>>
>>> If there's need for a specific Show instance for Vectors of Word8s we
>>> can always add one directly to vector. (Roman, what are your thoughts
>>> on this?)
>>
>> Personally, I think that ByteString and especially Vector Word8 aren't strings and shouldn't be treated as such. But I wouldn't be strongly against showing them as strings. However, I *am* strongly against using UndecidableInstances in vector and I don't see how to implement this without using them.
>
> I meant OverlappingInstances, of course. To clarify, I would still consider it if everybody thinks it's a really good idea.
>
> Roman
>
>
>

I agree that you shouldn't use ByteStrings or Vectors of Word8s for
Unicode strings. However I can imagine that for quick sessions in ghci
it can be quite handy if they are shown as strings. For example,
currently we have:

> import Network.HTTP.Enumerator
> simpleHttp "http://code.haskell.org/~basvandijk/"
Chunk "<html>\n<head><title>Bas van
Dijk</title></head>\n<body>\n<h1>Bas van Dijk</h1>\n\n<p>Email: <a
href=\"mailto://[hidden email]\">[hidden email]</a></p>\n\n<p>Nick
on IRC: <tt>basvandijk</tt></p>\n\n<a
href=\"http://www.haskellers.com/user/basvandijk/\">\n  <img
src=\"http://www.haskellers.com/static/badge.png\" \n       alt=\"I'm
a Haskeller\"\n       border=\"0\">\n</a>\n\n<p>See my <a
href=\"https://github.com/basvandijk\">GitHub</a> page for a list of
projects I work on.</p>\n\n</body>\n</html>\n" Empty

If ByteStrings were not shown as strings this would look like:

Chunk ( fromList
[60,104,116,109,108,62,10,60,104,101,97,100,62,60,116,105,116,108,101,62,66,97,115,32,118,97,110,32,68,105,106,107,60,47,116,105,116,108,101,62,60,47,104,101,97,100,62,10,60,98,111,100,121,62,10,60,104,49,62,66,97,115,32,118,97,110,32,68,105,106,107,60,47,104,49,62,10,10,60,112,62,69,109,97,105,108,58,32,60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,47,47,118,46,100,105,106,107,46,98,97,115,64,103,109,97,105,108,46,99,111,109,34,62,118,46,100,105,106,107,46,98,97,115,64,103,109,97,105,108,46,99,111,109,60,47,97,62,60,47,112,62,10,10,60,112,62,78,105,99,107,32,111,110,32,73,82,67,58,32,60,116,116,62,98,97,115,118,97,110,100,105,106,107,60,47,116,116,62,60,47,112,62,10,10,60,97,32,104,114,101,102,61,34,104,116,116,112,58,47,47,119,119,119,46,104,97,115,107,101,108,108,101,114,115,46,99,111,109,47,117,115,101,114,47,98,97,115,118,97,110,100,105,106,107,47,34,62,10,32,32,60,105,109,103,32,115,114,99,61,34,104,116,116,112,58,47,47,119,119,119,46,104,97,115,107,101,108,108,101,114,115,46,99,111,109,47,115,116,97,116,105,99,47,98,97,100,103,101,46,112,110,103,34,32,10,32,32,32,32,32,32,32,97,108,116,61,34,73,39,109,32,97,32,72,97,115,107,101,108,108,101,114,34,10,32,32,32,32,32,32,32,98,111,114,100,101,114,61,34,48,34,62,10,60,47,97,62,10,10,60,112,62,83,101,101,32,109,121,32,60,97,32,104,114,101,102,61,34,104,116,116,112,115,58,47,47,103,105,116,104,117,98,46,99,111,109,47,98,97,115,118,97,110,100,105,106,107,34,62,71,105,116,72,117,98,60,47,97,62,32,112,97,103,101,32,102,111,114,32,97,32,108,105,115,116,32,111,102,32,112,114,111,106,101,99,116,115,32,73,32,119,111,114,107,32,111,110,46,60,47,112,62,10,10,60,47,98,111,100,121,62,10,60,47,104,116,109,108,62,10])
Empty

Personally, I don't work in ghci that often so I don't care that much
if we have or don't have specialized Show instances for Vectors of
Word8s.

So what do other people think about this?

Bas

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: ANNOUNCE: vector-bytestring-0.0.0.0

Joachim Breitner-2
Hi,

Am Samstag, den 15.10.2011, 16:15 +0200 schrieb Bas van Dijk:
> So what do other people think about this?

having a human-readable Show instance for ByteStrings is definitely a
great plus when debugging code.

Greetings,
Joachim

--
Joachim "nomeata" Breitner
  [hidden email]  |  [hidden email]  |  GPG: 0x4743206C
  xmpp: [hidden email] | http://www.joachim-breitner.de/


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: ANNOUNCE: vector-bytestring-0.0.0.0

Ivan Lazar Miljenovic
In reply to this post by Bas van Dijk-2
On 16 October 2011 01:15, Bas van Dijk <[hidden email]> wrote:

>
> I agree that you shouldn't use ByteStrings or Vectors of Word8s for
> Unicode strings. However I can imagine that for quick sessions in ghci
> it can be quite handy if they are shown as strings. For example,
> currently we have:
>
>> import Network.HTTP.Enumerator
>> simpleHttp "http://code.haskell.org/~basvandijk/"
> Chunk "<html>\n<head><title>Bas van
> Dijk</title></head>\n<body>\n<h1>Bas van Dijk</h1>\n\n<p>Email: <a
> href=\"mailto://[hidden email]\">[hidden email]</a></p>\n\n<p>Nick
> on IRC: <tt>basvandijk</tt></p>\n\n<a
> href=\"http://www.haskellers.com/user/basvandijk/\">\n  <img
> src=\"http://www.haskellers.com/static/badge.png\" \n       alt=\"I'm
> a Haskeller\"\n       border=\"0\">\n</a>\n\n<p>See my <a
> href=\"https://github.com/basvandijk\">GitHub</a> page for a list of
> projects I work on.</p>\n\n</body>\n</html>\n" Empty
>
> If ByteStrings were not shown as strings this would look like:
>
> Chunk ( fromList
> [60,104,116,109,108,62,10,60,104,101,97,100,62,60,116,105,116,108,101,62,66,97,115,32,118,97,110,32,68,105,106,107,60,47,116,105,116,108,101,62,60,47,104,101,97,100,62,10,60,98,111,100,121,62,10,60,104,49,62,66,97,115,32,118,97,110,32,68,105,106,107,60,47,104,49,62,10,10,60,112,62,69,109,97,105,108,58,32,60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,47,47,118,46,100,105,106,107,46,98,97,115,64,103,109,97,105,108,46,99,111,109,34,62,118,46,100,105,106,107,46,98,97,115,64,103,109,97,105,108,46,99,111,109,60,47,97,62,60,47,112,62,10,10,60,112,62,78,105,99,107,32,111,110,32,73,82,67,58,32,60,116,116,62,98,97,115,118,97,110,100,105,106,107,60,47,116,116,62,60,47,112,62,10,10,60,97,32,104,114,101,102,61,34,104,116,116,112,58,47,47,119,119,119,46,104,97,115,107,101,108,108,101,114,115,46,99,111,109,47,117,115,101,114,47,98,97,115,118,97,110,100,105,106,107,47,34,62,10,32,32,60,105,109,103,32,115,114,99,61,34,104,116,116,112,58,47,47,119,119,119,46,104,97,115,107,101,108,108,101,114,115,46,99,111,109,47,115,116,97,116,105,99,47,98,97,100,103,101,46,112,110,103,34,32,10,32,32,32,32,32,32,32,97,108,116,61,34,73,39,109,32,97,32,72,97,115,107,101,108,108,101,114,34,10,32,32,32,32,32,32,32,98,111,114,100,101,114,61,34,48,34,62,10,60,47,97,62,10,10,60,112,62,83,101,101,32,109,121,32,60,97,32,104,114,101,102,61,34,104,116,116,112,115,58,47,47,103,105,116,104,117,98,46,99,111,109,47,98,97,115,118,97,110,100,105,106,107,34,62,71,105,116,72,117,98,60,47,97,62,32,112,97,103,101,32,102,111,114,32,97,32,108,105,115,116,32,111,102,32,112,114,111,106,101,99,116,115,32,73,32,119,111,114,107,32,111,110,46,60,47,112,62,10,10,60,47,98,111,100,121,62,10,60,47,104,116,109,108,62,10])
> Empty
>
> Personally, I don't work in ghci that often so I don't care that much
> if we have or don't have specialized Show instances for Vectors of
> Word8s.
>
> So what do other people think about this?

Actually, for my current use case of Bytestrings (binary encoding of
graphs using existing encoding schemes), I would prefer this
[Word8]-based Show instance as it would help with my debugging, since
the output looks along the lines of: Chunk (fromList
[3,2,3,0,3,1,3,0,2,2,1,0]).  I am the first to admit that my use case
is probably different from others though.

--
Ivan Lazar Miljenovic
[hidden email]
IvanMiljenovic.wordpress.com

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: ANNOUNCE: vector-bytestring-0.0.0.0

Ertugrul Söylemez
In reply to this post by Joachim Breitner-2
Joachim Breitner <[hidden email]> wrote:

> > So what do other people think about this?
>
> having a human-readable Show instance for ByteStrings is definitely a
> great plus when debugging code.

I agree and would even go as far as saying that it's generally useful,
even if the data is not guaranteed to be text.


Greets,
Ertugrul


--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe

signature.asc (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: ANNOUNCE: vector-bytestring-0.0.0.0

Ertugrul Söylemez
In reply to this post by Roman Leshchinskiy
Roman Leshchinskiy <[hidden email]> wrote:

> > Personally, I think that ByteString and especially Vector Word8
> > aren't strings and shouldn't be treated as such. But I wouldn't be
> > strongly against showing them as strings. However, I *am* strongly
> > against using UndecidableInstances in vector and I don't see how to
> > implement this without using them.
>
> I meant OverlappingInstances, of course. To clarify, I would still
> consider it if everybody thinks it's a really good idea.

My suggestion was to remove the generic Show instance and add only
specialized instances.  This is more work, but will also yield better
results.  In particular, it allows specialized string representations
for other types, too.  For example the way values of type Vector Bool
are printed is extremely useless.  I always find myself writing my own
debugging output functions for boolean vectors.


Greets,
Ertugrul


--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/



_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: ANNOUNCE: vector-bytestring-0.0.0.0

Bas van Dijk-2
On 15 October 2011 20:50, Ertugrul Soeylemez <[hidden email]> wrote:

> Roman Leshchinskiy <[hidden email]> wrote:
>
>> > Personally, I think that ByteString and especially Vector Word8
>> > aren't strings and shouldn't be treated as such. But I wouldn't be
>> > strongly against showing them as strings. However, I *am* strongly
>> > against using UndecidableInstances in vector and I don't see how to
>> > implement this without using them.
>>
>> I meant OverlappingInstances, of course. To clarify, I would still
>> consider it if everybody thinks it's a really good idea.
>
> My suggestion was to remove the generic Show instance and add only
> specialized instances.  This is more work, but will also yield better
> results.  In particular, it allows specialized string representations
> for other types, too.

What exactly is the problem with using OverlappingInstances to define
specialized Show and Read instances for Vectors with certain element
types (Char, Word8, Bool)?

Am I missing something dangerous here?

Bas

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: ANNOUNCE: vector-bytestring-0.0.0.0

Ertugrul Söylemez
Bas van Dijk <[hidden email]> wrote:

> > My suggestion was to remove the generic Show instance and add only
> > specialized instances.  This is more work, but will also yield
> > better results.  In particular, it allows specialized string
> > representations for other types, too.
>
> What exactly is the problem with using OverlappingInstances to define
> specialized Show and Read instances for Vectors with certain element
> types (Char, Word8, Bool)?
>
> Am I missing something dangerous here?

Consider having the following instances:

    instance Show a => Show (Vector a)
    instance Show (Vector Word8)

How could the compiler determine, which instance you want, when saying

    show someVector

where someVector :: Vector Word8?  Both instances are valid here, and
there is no mechanism to choose one of them.  You can only write a
generic instance, where you can rule out the specialized instances.  I
don't think that's possible in this case.


Greets,
Ertugrul


--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/



_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: ANNOUNCE: vector-bytestring-0.0.0.0

Bas van Dijk-2
On 15 October 2011 23:17, Ertugrul Soeylemez <[hidden email]> wrote:
> Both instances are valid here, and there is no mechanism to choose one of them.

There is: OverlappingInstances[1] chooses the most specific instance.
So in case someVector :: Vector Word8 the instance Show (Vector Word8)
is chosen because it's the most specific.

Bas

[1] http://www.haskell.org/ghc/docs/latest/html/users_guide/type-class-extensions.html#instance-overlap

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: ANNOUNCE: vector-bytestring-0.0.0.0

Stephen Tetley-2
On 15 October 2011 23:56, Bas van Dijk <[hidden email]> wrote:
> On 15 October 2011 23:17, Ertugrul Soeylemez <[hidden email]> wrote:
>> Both instances are valid here, and there is no mechanism to choose one of them.
>
> There is: OverlappingInstances[1] chooses the most specific instance.
> So in case someVector :: Vector Word8 the instance Show (Vector Word8)
> is chosen because it's the most specific.

This has the problem of incoherence in multi-module programs - GHC
might chose different instances for the same type depending on
compilation order. For a Show instance, this may be acceptable.

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: ANNOUNCE: vector-bytestring-0.0.0.0

Bas van Dijk-2
On 16 October 2011 08:51, Stephen Tetley <[hidden email]> wrote:

> On 15 October 2011 23:56, Bas van Dijk <[hidden email]> wrote:
>> On 15 October 2011 23:17, Ertugrul Soeylemez <[hidden email]> wrote:
>>> Both instances are valid here, and there is no mechanism to choose one of them.
>>
>> There is: OverlappingInstances[1] chooses the most specific instance.
>> So in case someVector :: Vector Word8 the instance Show (Vector Word8)
>> is chosen because it's the most specific.
>
> This has the problem of incoherence in multi-module programs - GHC
> might chose different instances for the same type depending on
> compilation order. For a Show instance, this may be acceptable.

But is this a problem when both instances are exported from the same
module and OverlappingInstances is only enabled in that module, as is
the case here?

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
123