Re: [Haskell-cafe] Re: Binary IO of a list of ints

2008-01-24 Thread Jamie Love



Stephan Walter wrote:

Hi,

On 2008-01-24 12:14, Jamie Love wrote:
  
I have a list of ints, with values between 0 and 255 and I need to print 
them out in little endian form to a file.



How about just using Data.Char.chr ?
  


Essentially because I need to control the byte ordering, and it has to 
be in the current case the opposite to my computer's native ordering 
(the file is a binary file).

Prelude let a = [32..64] :: [Int]
Prelude map Data.Char.chr a
 !\#$%'()*+,-./0123456789:;=?@


--Stephan

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


 

This message has been scanned for viruses and dangerous content 
by MailScanner and is believed to be clean.



  


--
Jamie Love
Senior Consultant
Aviarc Australia
Mobile: +61 400 548 048



 

This message has been scanned for viruses and dangerous content 
by MailScanner and is believed to be clean.


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


Re: [Haskell-cafe] Re: binary IO

2005-12-30 Thread Bulat Ziganshin
Hello Peter,

Thursday, December 29, 2005, 5:58:29 PM, you wrote:

PS The Fast I/O article I posted a few days ago is my
PS unfinished attempt at writing an efficient, general-purpose
PS binary I/O library for Haskell.

where i can find it?

-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]



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


Re: [Haskell-cafe] Re: binary IO

2005-12-28 Thread Joel Reymont
Amen! Haskell has forever realigned my mind-gears and I'm observing  
positive results as we speak :-).


On Dec 28, 2005, at 1:56 AM, Peter Simons wrote:


Even if you ultimately
decide to write your application in another language, you'll find
that knowing and understanding Haskell will change the way you
design software -- regardless of the language you use.


--
http://wagerlabs.com/





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


Re: [Haskell-cafe] Re: binary IO

2005-12-28 Thread Joel Reymont
I would compare Haskell to visiting the chiropractor. You will walk  
straighter, stand taller and your life will never be the same :D.


On Dec 28, 2005, at 1:56 AM, Peter Simons wrote:


you'll find
that knowing and understanding Haskell will change the way you
design software -- regardless of the language you use.


--
http://wagerlabs.com/





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


Re: [Haskell-cafe] Re: binary IO

2005-12-28 Thread Bulat Ziganshin
Hello Peter,

Tuesday, December 27, 2005, 11:26:29 PM, you wrote:

PS My guess is that you would learn more if _you_ would plug
PS the different IO libraries into your test code. I'm certain

Peter, because you claimed that Haskell can be made as effective as C,
please help us :)

your BlockIO library is great, but it's usage is limited to very
specific sutuations - when we can save pass state between processing
of individual bytes

what for (de)serialization tasks? my best attempts is still 10x slower
than C version. can you roll up little prototype for such library or
just sketch an ideas so i can try to implement it?

it is also call to everyone - what is the key to efficient Binary lib?
you can see my current attempt in http://freearc.narod.ru/Binary.tar.gz

the key functions:

instance (MemoryStream h) = ByteStream (BufferedMemoryStream h) where
vPutByte mem@(Buf h buf' pos' end') byte = do
pos - readPtr pos'
end - readPtr end'
if (pos==end) then do
sendCurrentBuffer mem
receiveNextBuffer mem
vPutByte mem byte
 else do
writePtr pos' $! (pos+:1)
writeByteAt pos $! (fromEnum byte)

vGetByte mem@(Buf h buf' pos' end') = do
pos - readPtr pos'
end - readPtr end'
if (pos==end) then do
sendCurrentBuffer mem
receiveNextBuffer mem
vGetByte mem
 else do
writePtr pos' $! (pos+:1)
byte - readByteAt pos
return $! (toEnum byte)

and series of getWordXX/putWordXX in class (ByteStream h) = BitStream h:

putWord32 h w = do vPutByte h $! ( w `shiftR` 24)
   vPutByte h $! ((w `shiftR` 16) .. 0xff)
   vPutByte h $! ((w `shiftR` 8)  .. 0xff)
   vPutByte h $! ( w  .. 0xff)
getWord32 h = do w1 - vGetByte h
 w2 - vGetByte h
 w3 - vGetByte h
 w4 - vGetByte h
 return $! ((w1 `shiftL` 24) .|.
(w2 `shiftL` 16) .|.
(w3 `shiftL`  8) .|.
(w4))

-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]



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


Re: [Haskell-cafe] Re: binary IO

2005-12-27 Thread Joel Reymont

I will have to leave this for a while. I apologize but I'm
more than a bit frustrated at the moment and it's not fair
of me to take it out on everybody else.

If someone is willing to take this further I will appreciate it,
otherwise I'll get to it in the coming weeks. Besides knowing
how to do it better I would like to know why it works poorly
as it is. So it's gonna take me a while.

Thanks, Joel

On Dec 27, 2005, at 8:26 PM, Peter Simons wrote:


My guess is that you would learn more if _you_ would plug
the different IO libraries into your test code. I'm certain
the respective library authors will be quite happy to answer
questions and to investigate unexpected results.


--
http://wagerlabs.com/





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