[Haskell-beginners] Compile type Error

emmanuel.delaborde emmanuel.delaborde at cimex.com
Thu Jan 29 10:25:59 EST 2009


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 ?

Thanks

E.







-----------------------------------------------------------------------------------------------

This e-mail (and any attachments) is confidential and may contain 
personal views which are not the views of Cimex Media Ltd and 
any affiliated companies, unless specifically stated. It is intended 
for the use of the individual or group to whom it is addressed. If 
you have received it in error, please delete it from your system, 
do not use, copy or disclose the information in any way nor act in 
reliance on it and please notify postmaster at cimex.com

A company registered in England  Wales. Company Number 03765711
Registered Office : The Olde Bakehouse, 156 Watling Street East, Towcester,
Northants NN12 6DB

This email was scanned by Postini, the leading provider in Managed Email Security.



More information about the Beginners mailing list