Re: [Haskell-cafe] class Bytestringable or ToBytestring

2012-11-24 Thread Vincent Hanquez

On 11/23/2012 08:19 AM, Silvio Frischknecht wrote:

i recently found the convertible package
Thanks. quite a cool package, I'll probably use it in the future for 
some of my programs.


Not sure that's appropriate for my cases unfortunately.

--
Vincent

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] class Bytestringable or ToBytestring

2012-11-23 Thread Silvio Frischknecht
i recently found the convertible package

http://hackage.haskell.org/packages/archive/convertible/1.0.11.1/doc/html/Data-
Convertible-Base.html

convert :: Convertible a b = a - b

I've only used it once but it looks good to me.

sure the type checker does not guartantee that you get a ByteString back but 
if you only use your own types where you write all the instances yourself you 
should be safe.

silvio

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] class Bytestringable or ToBytestring

2012-11-22 Thread Vincent Hanquez

Hi cafe,

I've been adding lots of types recently that looks more or less like:

newtype A = A ByteString
data B = B ByteString

This is great for extra type safety and letting the compiler do its job, 
however getting the bytestring back requires boiler plate.
At the moment either you give access to the constructor, which is not 
always wanted, or you use the record syntax to create a function to 
extract just the bytestring.
The latter is fine for 1 or 2 types, but the scheme fall apart when 
having many of those types and do pollute namespace.


I'm basically after something that looks like this:

class ToByteString a where
  toByteString :: a - ByteString

Before anyone suggest the Serialize interface from cereal or the Binary 
interface from binary which both looks quite similar (from far away):


- serialize work in the put monad, and you have to define a get 
instance: which is something that is not required or possible sometime.

- binary works with lazy bytestrings and got the same problem as cereal.
- a serialize instance that just do a single putByteString is really 
slow: 12 ns to 329 ns (26x time slower) on the same exact data on one 
isolated bench)

- neither of those packages are in the platform.

If that doesn't exists, could it be a worthy addition to bytestring ?
is this a good idea in general ?
is there any other way ?

Thanks,
--
Vincent

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] class Bytestringable or ToBytestring

2012-11-22 Thread kudah
Why not use

http://hackage.haskell.org/packages/archive/newtype/0.2/doc/html/Control-Newtype.html

instead?

On Thu, 22 Nov 2012 14:15:00 + Vincent Hanquez t...@snarc.org
wrote:

 Hi cafe,
 
 I've been adding lots of types recently that looks more or less like:
 
  newtype A = A ByteString
  data B = B ByteString
 
 This is great for extra type safety and letting the compiler do its
 job, however getting the bytestring back requires boiler plate.
 At the moment either you give access to the constructor, which is not 
 always wanted, or you use the record syntax to create a function to 
 extract just the bytestring.
 The latter is fine for 1 or 2 types, but the scheme fall apart when 
 having many of those types and do pollute namespace.
 
 I'm basically after something that looks like this:
 
  class ToByteString a where
toByteString :: a - ByteString
 
 Before anyone suggest the Serialize interface from cereal or the
 Binary interface from binary which both looks quite similar (from far
 away):
 
 - serialize work in the put monad, and you have to define a get 
 instance: which is something that is not required or possible
 sometime.
 - binary works with lazy bytestrings and got the same problem as
 cereal.
 - a serialize instance that just do a single putByteString is really 
 slow: 12 ns to 329 ns (26x time slower) on the same exact data on one 
 isolated bench)
 - neither of those packages are in the platform.
 
 If that doesn't exists, could it be a worthy addition to bytestring ?
 is this a good idea in general ?
 is there any other way ?
 
 Thanks,

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] class Bytestringable or ToBytestring

2012-11-22 Thread Vincent Hanquez

On 11/22/2012 03:42 PM, kudah wrote:

Why not use

http://hackage.haskell.org/packages/archive/newtype/0.2/doc/html/Control-Newtype.html

instead?
interesting i didn't know about it, however it's seems relatively 
unknown (can't find any library on hackage that use it) and just like 
Serialize and Binary the interface goes both way, where i'm looking only 
at the unpack method.


--
Vincent

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] class Bytestringable or ToBytestring

2012-11-22 Thread kudah
On Thu, 22 Nov 2012 21:14:31 + Vincent Hanquez t...@snarc.org
wrote:

 can't find any library on hackage that use it

http://packdeps.haskellers.com/reverse/newtype

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe