我有两个函数作用于字节字符串。第一个是Data.List中循环函数的字节串版本,第二个函数旋转字节串。
当我读取文件并将其输入发送到rotateBytes函数时,它会输出一个引号,然后我需要按Control-C来手动停止该功能。这是我的代码中的错误还是ghc中的错误?如何解决?
import qualified Data.ByteString as B
-- Cycle function for binary data
cycleBytes :: B.ByteString -> B.ByteString
cycleBytes xs
| B.null xs = error "cycleBytes: empty list"
| otherwise = xs' where xs' = xs `B.append` xs'
-- Rotate function for binary data
rotateBytes :: B.ByteString -> Int -> B.ByteString
rotateBytes xs n = B.take (B.length xs) $! B.drop (B.length xs + n) $! cycleBytes xs
目前使用该功能是这样的:
*Main> B.readFile "test.dat" >>= (\x -> return $ rotateBytes x 3)
"
^CInterrupted.