1 {-# LANGUAGE TypeFamilies, StandaloneDeriving, FlexibleInstances, FlexibleContexts, UndecidableInstances #-}
2 -- | This module declares some commonly used functions and instances.
13 import Data.Binary.Put
14 import qualified Data.ByteString.Lazy as B
15 import qualified Data.Map as M
21 instance Default B.ByteString where
24 instance Default Word16 where
27 toCharList :: B.ByteString -> [Int]
28 toCharList bstr = map fromIntegral $ B.unpack bstr
30 poolSize :: Pool stage -> Int
33 (!) :: (Ord k) => M.Map k a -> k -> a
36 showListIx :: (Show i, Show a) => [(i,a)] -> String
37 showListIx list = unlines $ map s list
38 where s (i, x) = show i ++ ":\t" ++ show x
40 byteString :: (Binary t) => t -> B.ByteString
41 byteString x = runPut (put x)
43 mapFindIndex :: (Num k) => (v -> Bool) -> M.Map k v -> Maybe k
44 mapFindIndex check m =
45 case find (check . snd) (M.assocs m) of