Couldn't match expected type `Data.ByteString.Internal.ByteString' with actual type `ByteString'

StackOverflow https://stackoverflow.com/questions/20733924

  •  20-09-2022
  •  | 
  •  

Pergunta

Running the following code:

import Crypto.BCrypt
import Data.ByteString.Lazy.Char8

main = do
  maybe_pwhash <- hashPasswordUsingPolicy slowerBcryptHashingPolicy (pack "hunter2")
  print $ maybe_pwhash

I get the following compilation error:

test.hs:5:70:
    Couldn't match expected type `Data.ByteString.Internal.ByteString'
                with actual type `ByteString'
    In the return type of a call of `pack'
    In the second argument of `hashPasswordUsingPolicy', namely
      `(C.pack "hunter2")'
    In a stmt of a 'do' block:
      maybe_pwhash <- hashPasswordUsingPolicy
                        slowerBcryptHashingPolicy (pack "hunter2")

I am confused because I don't see why there is a difference between a Data.ByteString.Internal.ByteString and a ByteString.

Foi útil?

Solução

According to the bcrypt docs, you should be using strict bytestrings

import Data.ByteString.Char8

instead of the lazy ones:

import Data.ByteString.Lazy.Char8
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top