string - 如何将StrLn 放入Data.ByteString.Internal.ByteString?

标签 string haskell io output

我正在学习 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/

相关文章:

string - 在 MATLAB 中检查字符串是否包含任何数字

swift 范围 : not including first element

java - 用Java写入文件时,文件无法保存在文件夹中

haskell - 从外部网络采样行为

python 使用字典函数计算字符串中的重复字符

parsing - John Hughes 的确定性 LL(1) 使用 Arrow 和错误进行解析

haskell - `Operator`字定义是什么?

haskell - yesod 中带有自定义验证的文件上传字段

linux - 如果我设置的计数大于我通过 read() 系统调用读取的文件大小怎么办?

c - 每个 str-function 缩写词/首字母缩略词是什么意思?