結果
問題 | No.8030 ミラー・ラビン素数判定法のテスト |
ユーザー | こまる |
提出日時 | 2020-11-21 09:07:23 |
言語 | Haskell (9.8.2) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 17,712 bytes |
コンパイル時間 | 423 ms |
コンパイル使用メモリ | 166,272 KB |
最終ジャッジ日時 | 2024-11-14 23:54:45 |
合計ジャッジ時間 | 830 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) Main.hs:31:1: error: [GHC-87110] Could not load module ‘Data.IntMap.Strict’. It is a member of the hidden package ‘containers-0.6.8’. Use -v to see a list of the files searched for. | 31 | import Data.IntMap.Strict (IntMap) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Main.hs:32:1: error: [GHC-87110] Could not load module ‘Data.IntMap.Strict’. It is a member of the hidden package ‘containers-0.6.8’. Use -v to see a list of the files searched for. | 32 | import qualified Data.IntMap.Strict as IntMap | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Main.hs:33:1: error: [GHC-87110] Could not load module ‘Data.IntSet’. It is a member of the hidden package ‘containers-0.6.8’. Use -v to see a list of the files searched for. | 33 | import Data.IntSet (IntSet) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Main.hs:34:1: error: [GHC-87110] Could not load module ‘Data.IntSet’. It is a member of the hidden package ‘containers-0.6.8’. Use -v to see a list of the files searched for. | 34 | import qualified Data.IntSet as IntSet | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Main.hs:35:1: error: [GHC-87110] Could not load module ‘Data.Map’. It is a member of the hidden package ‘containers-0.6.8’. Use -v to see a list of the files searched for. | 35 | import Data.Map (Map) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Main.hs:36:1: error: [GHC-87110] Could not load module ‘Data.Map’. It is a member of the hidden package ‘containers-0.6.8’. Use -v to see a list of the files searched for
ソースコード
{-# LANGUAGE BangPatterns #-} {-# LANGUAGE BinaryLiterals #-} {-# LANGUAGE DefaultSignatures #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE UndecidableInstances #-} import Control.Arrow import Control.Monad import Control.Monad.Cont import Control.Monad.Fix import Control.Monad.ST import Control.Monad.State import Data.Bits import Data.Bool import Data.Char import Data.Coerce import qualified Data.Foldable as F import Data.IORef import Data.Int import qualified Data.List as L import Data.Maybe import Data.STRef import Data.Word import GHC.Exts import System.CPUTime import System.IO import Unsafe.Coerce import Data.IntMap.Strict (IntMap) import qualified Data.IntMap.Strict as IntMap import Data.IntSet (IntSet) import qualified Data.IntSet as IntSet import Data.Map (Map) import qualified Data.Map as Map import Data.Set (Set) import qualified Data.Set as Set import qualified GHC.Integer.GMP.Internals as GMP import qualified GHC.Integer.Logarithms.Internals as LOG import qualified Data.ByteString as BS import qualified Data.ByteString.Builder as BSB import qualified Data.ByteString.Char8 as BSC8 import qualified Data.ByteString.Lazy as BSL import qualified Data.ByteString.Lazy.Char8 as BSLC8 import qualified Data.ByteString.Short as BSS import qualified Data.ByteString.Unsafe as BSU import qualified Data.Vector as V import qualified Data.Vector.Fusion.Stream.Monadic as VFSM import qualified Data.Vector.Generic as VG import qualified Data.Vector.Generic.Mutable as VGM import qualified Data.Vector.Mutable as VM import qualified Data.Vector.Unboxed as VU import qualified Data.Vector.Unboxed.Mutable as VUM main :: IO () main = do n <- readLn :: IO Int xs <- parseN1 n rep n $ \i -> do let x = xs VU.! i mr <- millerRabin x putBuilder $ BSB.intDec x <> bool " 0\n" " 1\n" mr millerRabin :: Int -> IO Bool millerRabin k | k <= 3 = return $ k == 2 || k == 3 | k .&. 1 == 0 = return False | otherwise = do mt19937 <- newMT19937 flip fix 4 $ \loop !i -> do a <- randomR mt19937 1 (k - 1) let allok = all (\r -> powModInt a ((1 .<<. r) * d) k /= m) [0 .. (s - 1)] if (powModInt a d k /= 1) && allok then return False else if i < 0 then return True else loop (i - 1) where !m = k - 1 !s = ctz m !d = m .>>. s _pointer :: Int _pointer = 312 {-# INLINE _pointer #-} _lowerMask :: Word64 _lowerMask = 0b0000000000000000000000000000000001111111111111111111111111111111 {-# INLINE _lowerMask #-} _upperMask :: Word64 _upperMask = 0b1111111111111111111111111111111110000000000000000000000000000000 {-# INLINE _upperMask #-} type MT19937 = VUM.IOVector Word64 newMT19937 :: IO MT19937 newMT19937 = do mt <- VUM.unsafeNew 313 :: IO MT19937 VUM.unsafeWrite mt _pointer 0 t <- fromInteger <$> getCPUTime VUM.unsafeWrite mt 0 (t * 0x3F9E31A) range 1 311 $ \mti -> do item <- VUM.unsafeRead mt (mti - 1) let rnd = 6364136223846793005 * (item .^. (item .>>. 62)) + unsafeCoerce @Int @Word64 mti VUM.unsafeWrite mt mti rnd return mt shiftAndXor :: Word64 -> Word64 shiftAndXor w0 = case w0 .^. ((w0 .>>. 29) .&. 0x5555555555555555) of w1 -> case w1 .^. ((w1 .<<. 17) .&. 0x71D67FFFEDA60000) of w2 -> case w2 .^. ((w2 .<<. 37) .&. 0xFFF7EEE000000000) of w3 -> w3 .^. (w3 .>>. 43) twist :: MT19937 -> IO () twist mt = do rep 312 $ \i -> do item1 <- VUM.unsafeRead mt i item2 <- VUM.unsafeRead mt ((i + 1) `mod` 312) let x = (item1 .&. _upperMask) + (item2 .&. _lowerMask) xA = x .>>. 1 xa = if odd x then xA .^. 0xB5026F5AA96619E9 else xA item3 <- VUM.unsafeRead mt ((i + 156) `mod` 312) VUM.unsafeWrite mt i (item3 .^. xa) VUM.unsafeWrite mt _pointer 0 nextWord64 :: MT19937 -> IO Word64 nextWord64 mt = do idx <- VUM.unsafeRead mt _pointer when (idx >= 312) $ twist mt y <- shiftAndXor <$> VUM.unsafeRead mt (fromIntegral idx) VUM.unsafeModify mt succ _pointer return y nextInt :: MT19937 -> IO Int nextInt mt = unsafeCoerce <$> nextWord64 mt nextWord :: MT19937 -> IO Word nextWord mt = unsafeCoerce <$> nextWord64 mt nextDouble :: MT19937 -> IO Double nextDouble mt19937 = do t <- nextWord64 mt19937 let x = 0x3ff .<<. 52 .|. t .>>. 12 return $! unsafeCoerce @Word64 @Double x - 1.0 nextGauss :: MT19937 -> Double -> Double -> IO Double nextGauss mt19937 mu sigma = do x <- nextDouble mt19937 y <- nextDouble mt19937 let z = sqrt (-2.0 * log x) * cos (2.0 * pi * y) return $! sigma * z + mu randomR :: MT19937 -> Int -> Int -> IO Int randomR mt19937 l r = (+ l) . flip mod (r - l + 1) <$> nextInt mt19937 shuffleM :: VUM.Unbox a => MT19937 -> VUM.IOVector a -> IO () shuffleM mt19937 mvec = do rev (VUM.length mvec) $ \i -> do j <- nextWord64 mt19937 VUM.unsafeSwap mvec i (unsafeCoerce $ rem j (unsafeCoerce i + 1)) shuffle :: VU.Unbox a => MT19937 -> VU.Vector a -> IO (VU.Vector a) shuffle mt19937 vec = do mv <- VU.unsafeThaw vec shuffleM mt19937 mv VU.unsafeFreeze mv powModInt :: Int -> Int -> Int -> Int powModInt a n mo = fI $ GMP.powModInteger (fi a) (fi n) (fi mo) {-# INLINE powModInt #-} recipModInt :: Int -> Int -> Int recipModInt a mo = fI $ GMP.recipModInteger (fi a) (fi mo) {-# INLINE recipModInt #-} fi :: Int -> Integer fi = fromIntegral {-# INLINE fi #-} fI :: Integer -> Int fI = fromInteger {-# INLINE fI #-} infixl 8 .<<., .>>., .>>>. infixl 6 .^. (.<<.) :: Bits b => b -> Int -> b (.<<.) = unsafeShiftL {-# INLINE (.<<.) #-} (.>>.) :: Bits b => b -> Int -> b (.>>.) = unsafeShiftR {-# INLINE (.>>.) #-} (.>>>.) :: Int -> Int -> Int (.>>>.) (I# x#) (I# i#) = I# (uncheckedIShiftRL# x# i#) {-# INLINE (.>>>.) #-} (.^.) :: Bits b => b -> b -> b (.^.) = xor {-# INLINE (.^.) #-} clz :: FiniteBits fb => fb -> Int clz = countLeadingZeros {-# INLINE clz #-} ctz :: FiniteBits fb => fb -> Int ctz = countTrailingZeros {-# INLINE ctz #-} encode32x2 :: Int -> Int -> Int encode32x2 x y = x .<<. 32 .|. y {-# INLINE encode32x2 #-} decode32x2 :: Int -> (Int, Int) decode32x2 xy = let !x = xy .>>>. 32 !y = xy .&. 0xffffffff in (x, y) {-# INLINE decode32x2 #-} ceilPow2 :: Int -> Int ceilPow2 n | n > 1 = (-1) .>>>. clz (n - 1) + 1 | otherwise = 1 {-# INLINE ceilPow2 #-} floorPow2 :: Int -> Int floorPow2 n | n >= 1 = 1 .<<. (63 - clz n) | otherwise = 0 {-# INLINE floorPow2 #-} bitReverse :: Int -> Int bitReverse = unsafeCoerce . step 32 0xffffffff00000000 0x00000000ffffffff . step 16 0xffff0000ffff0000 0x0000ffff0000ffff . step 08 0xff00ff00ff00ff00 0x00ff00ff00ff00ff . step 04 0xf0f0f0f0f0f0f0f0 0x0f0f0f0f0f0f0f0f . step 02 0xcccccccccccccccc 0x3333333333333333 . step 01 0xaaaaaaaaaaaaaaaa 0x5555555555555555 . unsafeCoerce where step :: Int -> Word64 -> Word64 -> Word64 -> Word64 step i ml mr = \ !x -> (x .&. ml) .>>. i .|. (x .&. mr) .<<. i {-# INLINE step #-} rep :: Monad m => Int -> (Int -> m ()) -> m () rep n = flip VFSM.mapM_ (streamG 0 (n - 1) const 0 (+) 1) {-# INLINE rep #-} rep' :: Monad m => Int -> (Int -> m ()) -> m () rep' n = flip VFSM.mapM_ (streamG 0 n const 0 (+) 1) {-# INLINE rep' #-} rep1 :: Monad m => Int -> (Int -> m ()) -> m () rep1 n = flip VFSM.mapM_ (streamG 1 (n - 1) const 0 (+) 1) {-# INLINE rep1 #-} rep1' :: Monad m => Int -> (Int -> m ()) -> m () rep1' n = flip VFSM.mapM_ (streamG 1 n const 0 (+) 1) {-# INLINE rep1' #-} rev :: Monad m => Int -> (Int -> m ()) -> m () rev n = flip VFSM.mapM_ (streamRG (n - 1) 0 const 0 (-) 1) {-# INLINE rev #-} rev' :: Monad m => Int -> (Int -> m ()) -> m () rev' n = flip VFSM.mapM_ (streamRG n 0 const 0 (-) 1) {-# INLINE rev' #-} rev1 :: Monad m => Int -> (Int -> m ()) -> m () rev1 n = flip VFSM.mapM_ (streamRG (n - 1) 1 const 0 (-) 1) {-# INLINE rev1 #-} rev1' :: Monad m => Int -> (Int -> m ()) -> m () rev1' n = flip VFSM.mapM_ (streamRG n 1 const 0 (-) 1) {-# INLINE rev1' #-} range :: Monad m => Int -> Int -> (Int -> m ()) -> m () range l r = flip VFSM.mapM_ (streamG l r const 0 (+) 1) {-# INLINE range #-} rangeR :: Monad m => Int -> Int -> (Int -> m ()) -> m () rangeR r l = flip VFSM.mapM_ (streamRG r l const 0 (-) 1) {-# INLINE rangeR #-} forP :: Monad m => Int -> (Int -> m ()) -> m () forP p = flip VFSM.mapM_ (streamG 2 p (^) 2 (+) 1) {-# INLINE forP #-} forG :: Monad m => Int -> Int -> (Int -> Int -> Int) -> Int -> (Int -> Int -> Int) -> Int -> (Int -> m ()) -> m () forG l r f p g d = flip VFSM.mapM_ (streamG l r f p g d) {-# INLINE forG #-} forRG :: Monad m => Int -> Int -> (Int -> Int -> Int) -> Int -> (Int -> Int -> Int) -> Int -> (Int -> m ()) -> m () forRG r l f p g d = flip VFSM.mapM_ (streamRG r l f p g d) {-# INLINE forRG #-} streamG :: Monad m => Int -> Int -> (Int -> Int -> Int) -> Int -> (Int -> Int -> Int) -> Int -> VFSM.Stream m Int streamG !l !r !f !p !g !d = VFSM.Stream step l where step x | f x p <= r = return $ VFSM.Yield x (g x d) | otherwise = return VFSM.Done {-# INLINE [0] step #-} {-# INLINE [1] streamG #-} streamRG :: Monad m => Int -> Int -> (Int -> Int -> Int) -> Int -> (Int -> Int -> Int) -> Int -> VFSM.Stream m Int streamRG !r !l !f !p !g !d = VFSM.Stream step r where step x | f x p >= l = return $ VFSM.Yield x (g x d) | otherwise = return VFSM.Done {-# INLINE [0] step #-} {-# INLINE [1] streamRG #-} withBreakIO :: ((r -> ContT r IO b) -> ContT r IO r) -> IO r withBreakIO = flip runContT pure . callCC {-# INLINE withBreakIO #-} withBreakST :: ((r -> ContT r (ST s) b) -> ContT r (ST s) r) -> (ST s) r withBreakST = flip runContT pure . callCC {-# INLINE withBreakST #-} type CParser a = StateT BSC8.ByteString Maybe a runCParser :: CParser a -> BSC8.ByteString -> Maybe (a, BSC8.ByteString) runCParser = runStateT {-# INLINE runCParser #-} int :: CParser Int int = coerce $ BSC8.readInt . BSC8.dropWhile isSpace {-# INLINE int #-} int1 :: CParser Int int1 = fmap (subtract 1) int {-# INLINE int1 #-} char :: CParser Char char = coerce BSC8.uncons {-# INLINE char #-} byte :: CParser Word8 byte = coerce BS.uncons {-# INLINE byte #-} skipSpaces :: CParser () skipSpaces = modify' (BSC8.dropWhile isSpace) {-# INLINE skipSpaces #-} seqInput :: Int -> IO (VU.Vector Int) seqInput n = VU.unfoldrN n (runCParser int) <$> BSC8.getLine {-# INLINE seqInput #-} parseN1 :: Int -> IO (VU.Vector Int) parseN1 n = VU.unfoldrN n (runCParser int) <$> BSC8.getContents {-# INLINE parseN1 #-} parseN2 :: Int -> IO (VU.Vector (Int, Int)) parseN2 n = VU.unfoldrN n (runCParser $ (,) <$> int <*> int) <$> BSC8.getContents {-# INLINE parseN2 #-} parseN3 :: Int -> IO (VU.Vector (Int, Int, Int)) parseN3 n = VU.unfoldrN n (runCParser $ (,,) <$> int <*> int <*> int) <$> BSC8.getContents {-# INLINE parseN3 #-} parseN4 :: Int -> IO (VU.Vector (Int, Int, Int, Int)) parseN4 n = VU.unfoldrN n (runCParser $ (,,,) <$> int <*> int <*> int <*> int) <$> BSC8.getContents {-# INLINE parseN4 #-} parseN5 :: Int -> IO (VU.Vector (Int, Int, Int, Int, Int)) parseN5 n = VU.unfoldrN n (runCParser $ (,,,,) <$> int <*> int <*> int <*> int <*> int) <$> BSC8.getContents {-# INLINE parseN5 #-} parseANBN :: Int -> IO (VU.Vector Int, VU.Vector Int) parseANBN n = VU.unzip . VU.unfoldrN n (runCParser $ (,) <$> int <*> int) <$> BSC8.getContents {-# INLINE parseANBN #-} parseANBNCN :: Int -> IO (VU.Vector Int, VU.Vector Int, VU.Vector Int) parseANBNCN n = VU.unzip3 . VU.unfoldrN n (runCParser $ (,,) <$> int <*> int <*> int) <$> BSC8.getContents {-# INLINE parseANBNCN #-} type Query3 = (Int, Int, Int) query3Parser :: CParser Query3 query3Parser = do skipSpaces t <- char case t of '0' -> (,,) 0 <$> int <*> int _ -> (,,) 1 <$> int <*> pure 0 parseQ3 :: Int -> IO (VU.Vector Query3) parseQ3 n = VU.unfoldrN n (runCParser query3Parser) <$> BSC8.getContents {-# INLINE parseQ3 #-} type Query5 = (Int, Int, Int, Int, Int) query5Parser :: CParser Query5 query5Parser = do skipSpaces t <- char case t of '0' -> (,,,,) 0 <$> int <*> int <*> int <*> int _ -> (,,,,) 1 <$> int <*> int <*> pure 0 <*> pure 0 parseQ5 :: Int -> IO (VU.Vector Query5) parseQ5 n = VU.unfoldrN n (runCParser query5Parser) <$> BSC8.getContents {-# INLINE parseQ5 #-} readInt :: BSC8.ByteString -> Int readInt = fst . fromJust . BSC8.readInt {-# INLINE readInt #-} getInt :: IO Int getInt = readInt <$> BSC8.getLine {-# INLINE getInt #-} readIntList :: BSC8.ByteString -> [Int] readIntList = map readInt . BSC8.words {-# INLINE readIntList #-} getIntList :: IO [Int] getIntList = readIntList <$> BSC8.getLine {-# INLINE getIntList #-} readInteger :: BSC8.ByteString -> Integer readInteger = fst . fromJust . BSC8.readInteger {-# INLINE readInteger #-} getInteger :: IO Integer getInteger = readInteger <$> BSC8.getLine {-# INLINE getInteger #-} readIntegerList :: BSC8.ByteString -> [Integer] readIntegerList = map readInteger . BSC8.words {-# INLINE readIntegerList #-} getIntegerList :: IO [Integer] getIntegerList = readIntegerList <$> BSC8.getLine {-# INLINE getIntegerList #-} class ShowAsBuilder a where showAsBuilder :: a -> BSB.Builder default showAsBuilder :: (Show a) => a -> BSB.Builder showAsBuilder = BSB.string8 . show instance ShowAsBuilder Int where showAsBuilder = BSB.intDec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Int8 where showAsBuilder = BSB.int8Dec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Int16 where showAsBuilder = BSB.int16Dec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Int32 where showAsBuilder = BSB.int32Dec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Int64 where showAsBuilder = BSB.int64Dec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Word8 where showAsBuilder = BSB.word8Dec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Word16 where showAsBuilder = BSB.word16Dec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Word32 where showAsBuilder = BSB.word32Dec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Word64 where showAsBuilder = BSB.word64Dec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Integer where showAsBuilder = BSB.integerDec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Float where showAsBuilder = BSB.floatDec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Double where showAsBuilder = BSB.doubleDec {-# INLINE showAsBuilder #-} instance (ShowAsBuilder a, VG.Vector v a) => ShowAsBuilder (v a) where showAsBuilder = v2BSpcSep putBuilder :: BSB.Builder -> IO () putBuilder = BSB.hPutBuilder stdout {-# INLINE putBuilder #-} printVecInLines :: (VG.Vector v a, ShowAsBuilder a) => v a -> IO () printVecInLines = putBuilder . v2BLines {-# INLINE printVecInLines #-} printVecInSpcSepLn :: (VG.Vector v a, ShowAsBuilder a) => v a -> IO () printVecInSpcSepLn = putBuilder . v2BSpcSepLn {-# INLINE printVecInSpcSepLn #-} v2BSpcSepLn :: (VG.Vector v a, ShowAsBuilder a) => v a -> BSB.Builder v2BSpcSepLn = v2BSpcSepLnWith showAsBuilder {-# INLINE v2BSpcSepLn #-} v2BSpcSep :: (VG.Vector v a, ShowAsBuilder a) => v a -> BSB.Builder v2BSpcSep = v2BSpcSepWith showAsBuilder {-# INLINE v2BSpcSep #-} v2BConcat:: (VG.Vector v a, ShowAsBuilder a) => v a -> BSB.Builder v2BConcat = v2BConcatWith showAsBuilder {-# INLINE v2BConcat #-} v2BLines:: (VG.Vector v a, ShowAsBuilder a) => v a -> BSB.Builder v2BLines = v2BLinesWith showAsBuilder {-# INLINE v2BLines #-} v2BSpcSepLnWith :: VG.Vector v a => (a -> BSB.Builder) -> v a -> BSB.Builder v2BSpcSepLnWith = v2BSpcSepPostfWith "\n" {-# INLINE v2BSpcSepLnWith #-} v2BSpcSepWith :: VG.Vector v a => (a -> BSB.Builder) -> v a -> BSB.Builder v2BSpcSepWith = v2BSpcSepPostfWith "" {-# INLINE v2BSpcSepWith #-} v2BConcatWith :: VG.Vector v a => (a -> BSB.Builder) -> v a -> BSB.Builder v2BConcatWith showFct = VG.foldr ((<>) . showFct) mempty {-# INLINE v2BConcatWith #-} v2BLinesWith :: VG.Vector v a => (a -> BSB.Builder) -> v a -> BSB.Builder v2BLinesWith showFct = VG.foldr (\a -> (showFct a <>) . (BSB.char7 '\n' <>)) mempty {-# INLINE v2BLinesWith #-} v2BSpcSepPostf :: (VG.Vector v a, ShowAsBuilder a) => BS.ByteString -> v a -> BSB.Builder v2BSpcSepPostf = (`v2BSpcSepPostfWith` showAsBuilder) {-# INLINE v2BSpcSepPostf #-} v2BSpcSepPostfWith :: VG.Vector v a => BS.ByteString -> (a -> BSB.Builder) -> v a -> BSB.Builder v2BSpcSepPostfWith = vecToBuilder "" " " {-# INLINE v2BSpcSepPostfWith #-} vecToBuilder :: VG.Vector v a => BS.ByteString -> BS.ByteString -> BS.ByteString -> (a -> BSB.Builder) -> v a -> BSB.Builder vecToBuilder !prefix !separator !postfix = vecToBuilder_ (BSB.byteString prefix) (BSB.byteString separator) (BSB.byteString postfix) {-# INLINE vecToBuilder #-} vecToBuilder_ :: VG.Vector v a => BSB.Builder -> BSB.Builder -> BSB.Builder -> (a -> BSB.Builder) -> v a -> BSB.Builder vecToBuilder_ !prefix !separator !postfix showFct vec = prefix <> VG.foldr (\a rest !prefx -> prefx <> (showFct a <> rest separator)) (const postfix) vec mempty {-# INLINE vecToBuilder_ #-}