我正在学习 Haskell,并决定尝试编写一些小型测试程序来习惯 Haskell 代码和使用模块。目前我正在尝试使用第一个参数来使用 Cypto.PasswordStore 创建密码哈希。为了测试我的程序,我试图从第一个参数创建一个散列,然后将散列打印到屏幕上。
import Crypto.PasswordStore
import System.Environment
main = do
args <- getArgs
putStrLn (makePassword (head args) 12)
我收到以下错误:
testmakePassword.hs:8:19:
Couldn't match expected type `String'
with actual type `IO Data.ByteString.Internal.ByteString'
In the return type of a call of `makePassword'
In the first argument of `putStrLn', namely
`(makePassword (head args) 12)'
In a stmt of a 'do' block: putStrLn (makePassword (head args) 12)
我一直在使用以下链接作为引用,但我现在只是试错无济于事。
http://hackage.haskell.org/packages/archive/bytestring/0.9.0.4/doc/html/Data-ByteString-Internal.html
http://hackage.haskell.org/packages/archive/pwstore-purehaskell/2.1/doc/html/Crypto-PasswordStore.html
最佳答案
您还没有导入 ByteString,所以它正在尝试使用 putStrLn 的 String 版本。
我提供了toBS
对于String->ByteString
转换。
尝试
import Crypto.PasswordStore
import System.Environment
import qualified Data.ByteString.Char8 as B
toBS = B.pack
main = do
args <- getArgs
makePassword (toBS (head args)) 12 >>= B.putStrLn
关于string - 如何将StrLn 放入Data.ByteString.Internal.ByteString?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13205192/