How do I putStrLn a Data.ByteString.Internal.ByteString?

做~自己de王妃 提交于 2019-12-05 06:15:18

You haven't imported ByteString, so it's trying to use the String version of putStrLn. I've provided toBS for the String->ByteString conversion.

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

You have to do two things differently. First, makePassword is in IO, so you need to bind the result to a name and then pass the name to the IO function. Secondly, you need to import IO functions from Data.ByteString

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

Or, if you won't be using the password result anywhere else, you can use bind to connect the two functions directly:

main = do
    args <- getArgs
    B.putStrLn =<< makePassword (B.pack $ head args) 12
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!