gameServer/Utils.hs
changeset 11838 8f730ba4ca3c
parent 11575 db7743e2fad1
child 12114 cdadc1d487f1
equal deleted inserted replaced
11837:c05e8453206a 11838:8f730ba4ca3c
    27 import Network.Socket
    27 import Network.Socket
    28 import System.IO
    28 import System.IO
    29 import qualified Data.List as List
    29 import qualified Data.List as List
    30 import Control.Monad
    30 import Control.Monad
    31 import qualified Data.ByteString.Lazy as BL
    31 import qualified Data.ByteString.Lazy as BL
    32 import qualified Text.Show.ByteString as BS
       
    33 import qualified Data.ByteString.Char8 as B
    32 import qualified Data.ByteString.Char8 as B
    34 import qualified Data.ByteString.UTF8 as UTF8
    33 import qualified Data.ByteString.UTF8 as UTF8
    35 import Data.Maybe
    34 import Data.Maybe
    36 -------------------------------------------------
    35 -------------------------------------------------
    37 import CoreTypes
    36 import CoreTypes
   130 unfoldrE f b  =
   129 unfoldrE f b  =
   131     case f b of
   130     case f b of
   132         Right (a, new_b) -> let (a', b') = unfoldrE f new_b in (a : a', b')
   131         Right (a, new_b) -> let (a', b') = unfoldrE f new_b in (a : a', b')
   133         Left new_b       -> ([], new_b)
   132         Left new_b       -> ([], new_b)
   134 
   133 
   135 showB :: (BS.Show a) => a -> B.ByteString
   134 showB :: (Show a) => a -> B.ByteString
   136 showB = B.concat . BL.toChunks . BS.show
   135 showB = B.pack . show
   137 
   136 
   138 readInt_ :: (Num a) => B.ByteString -> a
   137 readInt_ :: (Num a) => B.ByteString -> a
   139 readInt_ str =
   138 readInt_ str =
   140   case B.readInt str of
   139   case B.readInt str of
   141        Just (i, t) | B.null t -> fromIntegral i
   140        Just (i, t) | B.null t -> fromIntegral i