9

私は 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

4

2 に答える 2

5

ByteString をインポートしていないため、文字列バージョンの putStrLn を使用しようとしています。変換を提供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
于 2012-11-03T01:49:14.773 に答える
4

2 つの異なることを行う必要があります。まず、makePasswordIO にあるため、結果を名前にバインドしてから、その名前を IO 関数に渡す必要があります。次に、IO 関数をインポートする必要があります。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

または、パスワードの結果を他の場所で使用しない場合は、bind を使用して 2 つの関数を直接接続できます。

main = do
    args <- getArgs
    B.putStrLn =<< makePassword (B.pack $ head args) 12
于 2012-11-03T01:51:33.127 に答える