Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Haskell Serialization (Ashish Agarwal)
   2. Re:  Haskell Serialization (Stephen Tetley)
   3. Re:  Haskell Serialization (Daniel Fischer)
   4. Re:  Haskell Serialization (Daniel Fischer)
   5. Re:  Haskell Serialization (Stephen Tetley)
   6.  Re: Beginners Digest, Vol 23, Issue 13 (Tim Sears)


----------------------------------------------------------------------

Message: 1
Date: Tue, 11 May 2010 13:00:43 -0400
From: Ashish Agarwal <[email protected]>
Subject: Re: [Haskell-beginners] Haskell Serialization
To: Stephen Tetley <[email protected]>,  Daniel Fischer
        <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Thanks for your responses.

> Only it might give rise to confusion if somebody wants to transmit those
> types according to another protocol.

So are Binary instances perceived to be just for (de)serializing from/to
Haskell? Would it be better style for me to define a new type class with
methods getProt and putProt, where Prot is whatever protocol I'm supporting?


> numbers are always big-endian

I have been wondering about the difference in put/get instances of Word
types versus the getWord8be, getWord8le, etc. functions. Since the default
instances use big-endian, is there any difference between the following:

    get (0::Word8)
    getWord8be 0

What exactly are the guarantees for Binary instances, only that get and put
are inverses? Are all other features possibly different between compiler
versions or different implementations of Haskell?



On Mon, May 10, 2010 at 5:49 PM, Stephen Tetley <[email protected]>wrote:

> Hi Ashish
>
> Daniel has largely answered this for me (thanks Daniel!).
>
> If you define Binary instances for your data types to match a protocol
> - then as Daniel says you can only use them for that protocol.
> Similarly the all the regular Haskell types - Int, Word8, Float, etc.
> - have Binary instances ready-made which you may not want when dealing
> with anything non-Haskell [*]: numbers are always big-endian, the
> encodings for Integers, Floats and the like are sparsely documented
> and may well handle signs differently to an equivalent C / Java / ...
> representation.
>
> [*] Personally I'd go as far as saying, as saying you should avoid
> them entirely except for writing other instances of the Binary class.
>
> Best wishes
>
> Stephen
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100511/17cd6087/attachment-0001.html

------------------------------

Message: 2
Date: Tue, 11 May 2010 18:45:42 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Haskell Serialization
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

On 11 May 2010 18:00, Ashish Agarwal <[email protected]> wrote:
> Thanks for your responses.
>
>> Only it might give rise to confusion if somebody wants to transmit those
>> types according to another protocol.
> So are Binary instances perceived to be just for (de)serializing from/to
> Haskell? Would it be better style for me to define a new type class with
> methods getProt and putProt, where Prot is whatever protocol I'm supporting?

Hi Ashish

For the first question - my opinion would be yes, though I might be in
a minority of one on that point.

For the second question - its just a matter of taste, personally I
like type class to be a bit more than a naming convenience e.g. the
Monad class communicates a strong notion of, ahem, "monads" and there
are many valuable functions that can be built using just the
operations of monad class without knowing the implementation
(sequence, liftM, mapM etc.). For say pretty printing, I can live
happily just prefixing my type with pp rather than hankering after a
class (e.g ppInt, ppFloat, ppSyntaxTree...). Again this is an entirely
personal taste - and when a Pretty class is provided (as in wl-pprint,
but not HughesPJ) I use it.


> is there any difference between the following:
>     get (0::Word8)
>     getWord8be 0

Did you mean this, as there is no `getWord8`:

> get (0::Word8)
> getWord8 0

This will always be fine for a single Word8, as there's no notion of
endian-ness (as far as my understanding goes). Also the Binary
instance for Word8 is implemented as:

> instance Binary Word8 where
>   get = getWord8
>   put = putWord8

... so the code is the same.


An Int8 is a bit more problematic - I think works as 0x00 to 0x0E
covers 0..127, 0x10 is -128, going to 0xEE for -1. Whilst I think this
would be the expected behaviour in C, I can't remember if its true, so
I wouldn't like to rely on it for inter-working between Haskell and C.
For floating point numbers - representations are quite likely to
diverge, one would hope any good protocol would pick a proper
representation (e.g. IEEE-754).

Data.Binary is a "Standard Library" so any Haskell compiler should use
the same code and produce the same binary layout.

Best wishes

Stephen


------------------------------

Message: 3
Date: Tue, 11 May 2010 19:56:43 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Haskell Serialization
To: Ashish Agarwal <[email protected]>, [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="utf-8"

On Tuesday 11 May 2010 19:00:43, Ashish Agarwal wrote:
> Thanks for your responses.
>
> > Only it might give rise to confusion if somebody wants to transmit
> > those types according to another protocol.
>
> So are Binary instances perceived to be just for (de)serializing from/to
> Haskell?

Sort of. A Binary instance should be generic (for an  unspecified value of 
'generic'). Binary instances are for making the (de)serislisation of types 
using the type in question easy (and are expected to have as little 
overhead as possible - at least, that's what I expect).

> Would it be better style for me to define a new type class with
> methods getProt and putProt, where Prot is whatever protocol I'm
> supporting?
>

You don't need to define a new class, you could just use putProt and 
getProt directly.
However, if you are reasonably sure that (de)serialising your type 
according to a different protocol is exceptional, go ahead and make a 
Binary instance. If there are several standard protocols for a type, an 
instance using one could be confusing.

> > numbers are always big-endian
>
> I have been wondering about the difference in put/get instances of Word
> types versus the getWord8be, getWord8le, etc. functions. Since the
> default instances use big-endian, is there any difference between the
> following:
>
>     get (0::Word8)
>     getWord8be 0

Make that

put (0 :: Word16)
putWord16be 0

?

-- Words8s are written as bytes
instance Binary Word8 where
    put     = putWord8
    get     = getWord8

-- Words16s are written as 2 bytes in big-endian (network) order
instance Binary Word16 where
    put     = putWord16be
    get     = getWord16be

[analogously for other WordN types].
With optimisations, there should be no difference, without, the difference 
would be one dictionary lookup, I think.

>
> What exactly are the guarantees for Binary instances, only that get and
> put are inverses?

With hand-written instances, not even that :)

> Are all other features possibly different between
> compiler versions or different implementations of Haskell?

No, serialised values should be portable, i.e. if you serialise a value 
using implementation x and deserialise it using implementation y, you ought 
to get the same value.



------------------------------

Message: 4
Date: Tue, 11 May 2010 20:16:28 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Haskell Serialization
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="iso-8859-1"

On Tuesday 11 May 2010 19:45:42, Stephen Tetley wrote:
>
> An Int8 is a bit more problematic

Not really, the Binary instances for IntN just use fromIntegral to convert 
between IntN and WordN before serialising/after deserialising a WordN.
Now, it's not written in the language definition that fromIntegral should 
be a reinterpretation of the bit-pattern for these conversions, but I think 
you can pretty much rely on that.

What might be a problem for the unwary are the instance for Int and Word 
(guess what they do and why).


> I wouldn't like to rely on it for inter-working between Haskell and C.

Int8 and Word8 are unproblematic (unless you have a ones-complement 
machine), the problems appear only for larger types, as there's no 
guarantee whether your architecture is big-endian or little-endian. But if 
you know that, you know what to do on the C end.

> For floating point numbers - representations are quite likely to
> diverge, one would hope any good protocol would pick a proper
> representation (e.g. IEEE-754).
>
> Data.Binary is a "Standard Library" so any Haskell compiler should use
> the same code and produce the same binary layout.
>
> Best wishes
>
> Stephen



------------------------------

Message: 5
Date: Tue, 11 May 2010 20:01:19 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Haskell Serialization
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

On 11 May 2010 19:16, Daniel Fischer <[email protected]> wrote:

> Int8 and Word8 are unproblematic (unless you have a ones-complement
> machine), the problems appear only for larger types, [SNIP]


Hi Daniel

Likely I was revealing a personal bias on that one, the only protocol
I've implemented where Int8 has featured has been MIDI.

If MIDI isn't ones-complement, my codes - I've written decoders /
encoders several times - have been wrong for years...

Best wishes

Stephen


------------------------------

Message: 6
Date: Tue, 11 May 2010 15:16:19 -0400
From: Tim Sears <[email protected]>
Subject: [Haskell-beginners] Re: Beginners Digest, Vol 23, Issue 13
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

Thanks. Here you go. --Tim


-------------- next part --------------
A non-text attachment was scrubbed...
Name: trans-mark5.model
Type: application/octet-stream
Size: 45146 bytes
Desc: not available
Url : 
http://www.haskell.org/pipermail/beginners/attachments/20100511/bdaaf393/trans-mark5.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: trans-mark5.xmodel
Type: application/octet-stream
Size: 730677 bytes
Desc: not available
Url : 
http://www.haskell.org/pipermail/beginners/attachments/20100511/bdaaf393/trans-mark5-0001.obj
-------------- next part --------------

On May 11, 2010, at 12:00 PM, [email protected] wrote:

> Send Beginners mailing list submissions to
>       [email protected]
>
> To subscribe or unsubscribe via the World Wide Web, visit
>       http://www.haskell.org/mailman/listinfo/beginners
> or, via email, send a message with subject or body 'help' to
>       [email protected]
>
> You can reach the person managing the list at
>       [email protected]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Beginners digest..."
>
>
> Today's Topics:
>
>   1. Re:  Haskell Serialization (Ashish Agarwal)
>   2. Re:  Problem installing Haskell platform on Ubuntu       Karmic
>      (Ashish Agarwal)
>   3. Re:  Haskell Serialization (Daniel Fischer)
>   4. Re:  Haskell Serialization (Stephen Tetley)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 10 May 2010 15:00:14 -0400
> From: Ashish Agarwal <[email protected]>
> Subject: Re: [Haskell-beginners] Haskell Serialization
> To: Stephen Tetley <[email protected]>
> Cc: [email protected]
> Message-ID:
>       <[email protected]>
> Content-Type: text/plain; charset="iso-8859-1"
>
>> the Binary class as it is specialized to serializing values for  
>> Haskell
> only
>
> Can you please expand on this? I've been using Data.Binary to  
> (de)serialize
> messages for some networking protocols, and have made all my types  
> instances
> of Binary. Non-Haskell programs will be receiving and sending  
> messages on
> one end, but I didn't think that mattered since my get and put  
> functions are
> written to adhere to the protocol's definition. Is there some issue  
> I'm
> missing?
>
>
> On Mon, May 10, 2010 at 6:18 AM, Stephen Tetley <[email protected] 
> >wrote:
>
>> Hi Tom
>>
>> If you are interfacing with non-Haskell binary objects - you will  
>> want
>> binary parsing / writing rather than simple serialization as the
>> format will be determined by the foreign objects.
>>
>> You can still use Data.Binary (indeed its probably the best choice),
>> but you will want to use the modules Data.Binary.Get and
>> Data.Binary.Put directly and probably avoid the Binary class as it is
>> specialized to serializing values for Haskell only.
>>
>> There are probably quite a few libraries on Hackage that you can look
>> at for examples, though there might be more packages that supply
>> parsers only and don't do writing, e.g:
>>
>> http://hackage.haskell.org/package/pecoff  (Parser only)
>>
>> There will be more among the packages this list that directly  
>> depend on
>> Binary:
>>
>> http://bifunctor.homelinux.net/~roel/cgi-bin/hackage-scripts/revdeps/binary-0.5.0.2#direct
>>
>>
>> Best wishes
>>
>> Stephen
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: 
> http://www.haskell.org/pipermail/beginners/attachments/20100510/a2c53f1c/attachment-0001.html
>
> ------------------------------
>
> Message: 2
> Date: Mon, 10 May 2010 15:23:54 -0400
> From: Ashish Agarwal <[email protected]>
> Subject: Re: [Haskell-beginners] Problem installing Haskell platform
>       on Ubuntu       Karmic
> To: Kim Stebel <[email protected]>
> Cc: [email protected]
> Message-ID:
>       <[email protected]>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Try: "ghc-pkg unregister parsec". I think this will cause parsec to  
> get
> recompiled. I had a similar problem and recall having to do this  
> with a few
> libraries, although this was during compilation of cabal.
>
>
> On Sun, Apr 4, 2010 at 2:20 AM, Kim Stebel  
> <[email protected]>wrote:
>
>> Hello List,
>>
>> I can't compile the haskell platform. I followed this guide
>> http://davidsiegel.org/haskell-platform-in-karmic-koala/ and  
>> downloaded
>> http://hackage.haskell.org/platform/2010.1.0.0/haskell-platform-2010.1.0.0.tar.gzas
>>  
>>  suggested in comment 5. configure runs fine, but when I try to  
>> "make" it,
>> it fails to compile the network package.
>>
>> Preprocessing library network-2.2.1.7...
>> Building network-2.2.1.7...
>> [1 of 5] Compiling Network.URI      ( Network/URI.hs,
>> dist/build/Network/URI.o )
>> [2 of 5] Compiling Network.Socket.Internal (
>> dist/build/Network/Socket/Internal.hs, dist/build/Network/Socket/ 
>> Internal.o
>> )
>> [3 of 5] Compiling Network.Socket   ( dist/build/Network/Socket.hs,
>> dist/build/Network/Socket.o )
>> [4 of 5] Compiling Network.BSD      ( dist/build/Network/BSD.hs,
>> dist/build/Network/BSD.o )
>> [5 of 5] Compiling Network          ( Network.hs, dist/build/ 
>> Network.o )
>>
>> Network.hs:274:15:
>>   Warning: Pattern match(es) are overlapped
>>            In a case alternative: a -> ...
>>
>> Network/URI.hs:108:7:
>>   Could not find module `Text.ParserCombinators.Parsec':
>>     Perhaps you haven't installed the profiling libraries for package
>> `parsec-2.1.0.1'?
>>     Use -v to see a list of the files searched for.
>>
>> Error:
>> Building the network-2.2.1.7 package failed
>> make: *** [build.stamp] Error 2
>>
>>
>> I'd really appreciate any help.
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: 
> http://www.haskell.org/pipermail/beginners/attachments/20100510/e937a1ce/attachment-0001.html
>
> ------------------------------
>
> Message: 3
> Date: Mon, 10 May 2010 21:28:01 +0200
> From: Daniel Fischer <[email protected]>
> Subject: Re: [Haskell-beginners] Haskell Serialization
> To: [email protected]
> Message-ID: <[email protected]>
> Content-Type: text/plain;  charset="utf-8"
>
> On Monday 10 May 2010 21:00:14, Ashish Agarwal wrote:
>>> the Binary class as it is specialized to serializing values for
>>> Haskell
>>
>> only
>>
>> Can you please expand on this? I've been using Data.Binary to
>> (de)serialize messages for some networking protocols, and have made  
>> all
>> my types instances of Binary. Non-Haskell programs will be  
>> receiving and
>> sending messages on one end, but I didn't think that mattered since  
>> my
>> get and put functions are written to adhere to the protocol's
>> definition. Is there some issue I'm missing?
>>
>
> I think the point was that
>
> derive (.., Binary)
>
> isn't a good idea when communicating with the Non-Haskell part of the
> world. If you write serialisation functions adhering to a specified
> protocol, defining a Binary instance for your types with those  
> functions
> isn't going to do harm.
> Only it might give rise to confusion if somebody wants to transmit  
> those
> types according to another protocol.
>
>
> ------------------------------
>
> Message: 4
> Date: Mon, 10 May 2010 22:49:45 +0100
> From: Stephen Tetley <[email protected]>
> Subject: Re: [Haskell-beginners] Haskell Serialization
> Cc: [email protected]
> Message-ID:
>       <[email protected]>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi Ashish
>
> Daniel has largely answered this for me (thanks Daniel!).
>
> If you define Binary instances for your data types to match a protocol
> - then as Daniel says you can only use them for that protocol.
> Similarly the all the regular Haskell types - Int, Word8, Float, etc.
> - have Binary instances ready-made which you may not want when dealing
> with anything non-Haskell [*]: numbers are always big-endian, the
> encodings for Integers, Floats and the like are sparsely documented
> and may well handle signs differently to an equivalent C / Java / ...
> representation.
>
> [*] Personally I'd go as far as saying, as saying you should avoid
> them entirely except for writing other instances of the Binary class.
>
> Best wishes
>
> Stephen
>
>
> ------------------------------
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
> End of Beginners Digest, Vol 23, Issue 13
> *****************************************


------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 23, Issue 14
*****************************************

Reply via email to