Compile type Error

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Compile type Error

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 ?

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 [hidden email]

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.

Reply | Threaded
Open this post in threaded view
|

Compile type Error

Rafael Gustavo da Cunha Pereira Pinto-2
I didn't compile, but, by the looks of it, I would change

import qualified Data.ByteString as BS (readFile)

for

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


as it seems sha1 needs a lazy bytestring

On Thu, Jan 29, 2009 at 13:25, emmanuel.delaborde <
[hidden email]> wrote:

> 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 containpersonal
> views which are not the views of Cimex Media Ltd andany affiliated
> companies, unless specifically stated. It is intendedfor the use of the
> individual or group to whom it is addressed. Ifyou have received it in
> error, please delete it from your system,do not use, copy or disclose the
> information in any way nor act inreliance on it and please notify
> [hidden email]
>
> 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.
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/beginners
>



--
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090129/2bcbe134/attachment-0001.htm
Reply | Threaded
Open this post in threaded view
|

Compile type Error

Daniel Fischer-4
In reply to this post by emmanuel.delaborde
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