[Haskell-beginners] Compile type Error

Daniel Fischer daniel.is.fischer at web.de
Thu Jan 29 11:41:06 EST 2009


Am Donnerstag, 29. Januar 2009 16:25 schrieb emmanuel.delaborde:
> Hello
>
> I have the following snippet :
>
> ----------------------------------------------------------
>
> module Main where
>
> import System.Environment (getArgs)
> import Data.Digest.OpenSSL.MD5 (md5sum)
> import Data.Digest.Pure.SHA (sha1, showDigest)
> import qualified Data.ByteString 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 fails to compile, this is the error I get :
>
>
> checksum.hs:20:19:
>      Couldn't match expected type
> `Data.ByteString.Lazy.Internal.ByteString'
>             against inferred type `Data.ByteString.Internal.ByteString'
>      In the first argument of `f', namely `fileBS'
>      In the expression: f fileBS
>      In the definition of `fileHash': fileHash = f fileBS
>
>
>
>
> it looks like  (showDigest . sha1) expects
> Data.ByteString.Lazy.Internal.ByteString but gets
> Data.ByteString.Internal.ByteString
>
> What can I do ?

import qualified Data.ByteString.Lazy as BS (readFile)

should do it.

>
> Thanks
>
> E.

Cheers,
Daniel



More information about the Beginners mailing list