module Main where
import System.Environment (getArgs)
import Data.Digest.OpenSSL.MD5 (md5sum)
import Data.Digest.Pure.SHA (sha1, showDigest)
import qualified Data.ByteString.Lazy as BS (readFile)
-- sha1 :: ByteString -> Digest
-- readFile :: FilePath -> IO ByteString
-- md5sum :: ByteString -> String
-- showDigest :: Digest -> String
checkHash :: String -> String -> String -> IO ()
checkHash codec hash file =
let f = case codec of
"md5" -> md5sum
"sha1" -> showDigest . sha1
_ -> error "Codec must be md5 or sha1 !" in
BS.readFile file >>= \fileBS ->
let fileHash = f fileBS in
print (hash == fileHash)
main =
getArgs >>= \as ->
case as of
(codec:hash:file:_) -> checkHash codec hash file
_ -> usage
usage = print "checksum codec hash file"
------
which now fails to compile with this error :
checksum.hs:17:22:
Couldn't match expected type `Data.ByteString.Internal.ByteString'
against inferred type `Data.ByteString.Lazy.Internal.ByteString'
In the expression: showDigest . sha1
In a case alternative: "sha1" -> showDigest . sha1
In the expression:
case codec of {
"md5" -> md5sum
"sha1" -> showDigest . sha1
_ -> error "Codec must be md5 or sha1 !" }
How can I both use md5sum and sha1 when one use a lazy ByteString end the other one does not ?
Thanks
E