我正在学习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
发布于 2012-11-03 09:49:15
您尚未导入ByteString,因此它尝试使用putStrLn的字符串版本。我已经为String->ByteString转换提供了toBS。
试一试
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发布于 2012-11-03 09:51:33
你必须做两件不同的事情。首先,makePassword在IO中,所以您需要将结果绑定到一个名称,然后将该名称传递给IO函数。其次,您需要从Data.ByteString导入IO函数
import Crypto.PasswordStore
import System.Environment
import qualified Data.ByteString as B
main = do
args <- getArgs
pwd <- makePassword (B.pack $ head args) 12
B.putStrLn pwd或者,如果您不想在其他任何地方使用密码结果,则可以使用bind直接连接这两个函数:
main = do
args <- getArgs
B.putStrLn =<< makePassword (B.pack $ head args) 12https://stackoverflow.com/questions/13205192
复制相似问题