You can use ByteString effectively, given that B.take and B.drop are O(1) operations:
import Data.ByteString (ByteString) import qualified Data.ByteString as B chunk :: Int -> ByteString -> [ByteString] chunk k = takeWhile (not . B.null) . map (B.take k) . iterate (B.drop k)
then
\> :set -XOverloadedStrings \> chunk 4 "abcdefghijkl" ["abcd","efgh","ijkl"]
the rest will be to display a list converted to the desired type from the desired, and one call to B.concat at the end.
A possible fromByteString can be implemented using bit shifts and left folds:
import Data.Bits (Bits, shiftL, (.|.)) fromByteString :: (Num a, Bits a) => ByteString -> a fromByteString = B.foldl go 0 where go acc i = (acc `shiftL` 8) .|. (fromIntegral i)
then
\> map fromByteString $ chunk 4 "abcdefghijkl" :: [Word32] [1633837924,1701209960,1768581996]
source share