我有两个作用于字节字符串的两个函数。第一个是 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.