[commit: packages/binary] master: Use getIntX/putIntX in the Binary class instances. (8b1459e)

git at git.haskell.org git at git.haskell.org
Tue Feb 2 21:04:56 UTC 2016


Repository : ssh://git@git.haskell.org/binary

On branch  : master
Link       : http://git.haskell.org/packages/binary.git/commitdiff/8b1459ed8033e72b6ef243649adf71c8d4909f33

>---------------------------------------------------------------

commit 8b1459ed8033e72b6ef243649adf71c8d4909f33
Author: Lennart Kolmodin <kolmodin at gmail.com>
Date:   Tue Jan 26 20:23:34 2016 +0100

    Use getIntX/putIntX in the Binary class instances.


>---------------------------------------------------------------

8b1459ed8033e72b6ef243649adf71c8d4909f33
 src/Data/Binary/Class.hs | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/Data/Binary/Class.hs b/src/Data/Binary/Class.hs
index f3c2d70..0eecfcb 100644
--- a/src/Data/Binary/Class.hs
+++ b/src/Data/Binary/Class.hs
@@ -209,35 +209,35 @@ instance Binary Word64 where
 
 -- Int8s are written as a single byte.
 instance Binary Int8 where
-    put i   = put (fromIntegral i :: Word8)
-    get     = liftM fromIntegral (get :: Get Word8)
+    put     = putInt8
+    get     = getInt8
 
 -- Int16s are written as a 2 bytes in big endian format
 instance Binary Int16 where
-    put i   = put (fromIntegral i :: Word16)
-    get     = liftM fromIntegral (get :: Get Word16)
+    put     = putInt16be
+    get     = getInt16be
 
 -- Int32s are written as a 4 bytes in big endian format
 instance Binary Int32 where
-    put i   = put (fromIntegral i :: Word32)
-    get     = liftM fromIntegral (get :: Get Word32)
+    put     = putInt32be
+    get     = getInt32be
 
 -- Int64s are written as a 8 bytes in big endian format
 instance Binary Int64 where
-    put i   = put (fromIntegral i :: Word64)
-    get     = liftM fromIntegral (get :: Get Word64)
+    put     = putInt64be
+    get     = getInt64be
 
 ------------------------------------------------------------------------
 
 -- Words are are written as Word64s, that is, 8 bytes in big endian format
 instance Binary Word where
-    put i   = put (fromIntegral i :: Word64)
-    get     = liftM fromIntegral (get :: Get Word64)
+    put     = putWord64be . fromIntegral
+    get     = liftM fromIntegral getWord64be
 
 -- Ints are are written as Int64s, that is, 8 bytes in big endian format
 instance Binary Int where
-    put i   = put (fromIntegral i :: Int64)
-    get     = liftM fromIntegral (get :: Get Int64)
+    put     = putInt64be . fromIntegral
+    get     = liftM fromIntegral getInt64be
 
 ------------------------------------------------------------------------
 --



More information about the ghc-commits mailing list