我如何把一个Data

我如何把一个Data

本文介绍了我如何把一个Data.ByteString.Internal.ByteString放入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习haskell,并决定尝试编写一些小测试程序来使用Haskell代码和使用模块。目前我正尝试使用第一个参数来使用Cypto.PasswordStore创建密码哈希。为了测试我的程序,我试图从第一个参数创建一个散列,然后将散列打印到屏幕上。

  import Crypto.PasswordStore 
import System.Environment
$ b $ main = do
args< - getArgs
putStrLn(makePassword(head args)12)

我收到以下错误:

  testmakePassword.hs:8:19:
实际类型为`IO Data.ByteString.Internal.ByteString'
的预期类型'String'
无法匹配在返回'makePassword'调用的类型
在`putStrLn'的第一个参数中,即
`(makePassword(head args)12)'
在'do'块的句柄中: putStrLn(makePassword(head args)12)

我一直使用以下链接作为参考,但是我我现在只是试错,无济于事。

解决方案

您尚未导入ByteString,因此它试图使用putStrLn的字符串版本。
我为字符串 - > ByteString 转换提供了 toBS



尝试

 导入Crypto.PasswordStore 
导入System.Environment
将合格的Data.ByteString.Char8导入为B
$ b到BS = B.pack

main = do
args< - getArgs
makePassword(toBS( head args))12>> = B.putStrLn


I'm learning haskell and decided to try writing some small test programs to get use to Haskell code and using modules. Currently I'm trying to use the first argument to create a password hash using the Cypto.PasswordStore. To test out my program I'm trying to create a hash from the first argument and then print the hash to screen.

import Crypto.PasswordStore
import System.Environment

main = do
    args <- getArgs
    putStrLn (makePassword (head args) 12)

I'm getting the following error:

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)

I've been using the following links as references but I am now just trial-erroring to no avail.http://hackage.haskell.org/packages/archive/bytestring/0.9.0.4/doc/html/Data-ByteString-Internal.htmlhttp://hackage.haskell.org/packages/archive/pwstore-purehaskell/2.1/doc/html/Crypto-PasswordStore.html

解决方案

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

这篇关于我如何把一个Data.ByteString.Internal.ByteString放入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 01:52