我该如何编写一个函数,其定义类似于...
readBinaryFile :: Filename -> IO Data.ByteString
我已经掌握了Haskell的功能部分,但是类型系统和单子(monads)仍然让我感到困惑。有人能为我编写并解释一下该函数如何工作吗?
readBinaryFile :: Filename -> IO Data.ByteString
我已经掌握了Haskell的功能部分,但是类型系统和单子(monads)仍然让我感到困惑。有人能为我编写并解释一下该函数如何工作吗?
import Data.ByteString.Lazy
readFile fp
很简单。如果你不希望字符串变得懒惰,就把懒惰的东西去掉。
import Data.ByteString.Lazy as BS
import Data.Word
import Data.Bits
fileToWordList :: String -> IO [Word8]
fileToWordList fp = do
contents <- BS.readFile fp
return $ unpack contents
readBinaryFile :: 文件名 -> IO Data.ByteString
这只是Data.ByteString.readFile
函数,在bytestring
包中,您不必编写此函数。