我正在学习 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/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 http://hackage.haskell.org/packages/archive/pwstore-purehaskell/2.1/doc/html/Crypto-PasswordStore.html
您尚未导入 ByteString,因此它尝试使用 putStrLn 的 String 版本。
我已经提供了toBS
为了String->ByteString
转换。
Try
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)