<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 29 Jan 2009, at 16:10, <a href="mailto:beginners-request@haskell.org">beginners-request@haskell.org</a> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; ">Content-Type: text/plain; charset="iso-8859-1"<br><br>I didn't compile, but, by the looks of it, I would change<br><br>import qualified Data.ByteString as BS (readFile)<br><br>for<br><br>import qualified Data.ByteString.Lazy as BS (readFile)<br><br><br>as it seems sha1 needs a lazy bytestring</span></blockquote><br></div><div><br></div><div><br></div><div>Thanks !&nbsp;</div><div>It compiles now but brings me to my real problem :)</div><div>If I uncomment this line</div><div><br></div><div>"md5" &nbsp;-> md5sum</div><div><br></div><div>I get the following :</div><div><br></div><div>------</div><div><br></div><div><div>module Main where</div><div><br></div><div>import System.Environment (getArgs)</div><div>import Data.Digest.OpenSSL.MD5 (md5sum)</div><div>import Data.Digest.Pure.SHA (sha1, showDigest)</div><div>import qualified Data.ByteString.Lazy as BS (readFile)</div><div><br></div><div>-- sha1 :: ByteString -> Digest</div><div>-- readFile :: FilePath -> IO ByteString</div><div>-- md5sum :: ByteString -> String</div><div>-- showDigest :: Digest -> String</div><div><br></div><div>checkHash :: String -> String -> String -> IO ()</div><div>checkHash codec hash file =&nbsp;</div><div>&nbsp;&nbsp;let f = case codec of&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"md5" &nbsp;-> md5sum&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"sha1" -> showDigest . sha1</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_ &nbsp; &nbsp; &nbsp;-> error "Codec must be md5 or sha1 !" in</div><div>&nbsp;&nbsp;BS.readFile file >>= \fileBS -></div><div>&nbsp;&nbsp;let fileHash = f fileBS in</div><div>&nbsp;&nbsp;print (hash == fileHash)</div><div>&nbsp;&nbsp;</div><div>main =&nbsp;</div><div>&nbsp;&nbsp;getArgs >>= \as -></div><div>&nbsp;&nbsp;case as of&nbsp;</div><div>&nbsp;&nbsp; &nbsp;(codec:hash:file:_) -> checkHash codec hash file</div><div>&nbsp;&nbsp; &nbsp;_ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-> usage</div><div><br></div><div>usage = print "checksum codec hash file"</div><div><br></div><div>------</div><div><br></div><div>which now fails to compile with this error &nbsp;:</div><div><br></div><div><div>checksum.hs:17:22:</div><div>&nbsp;&nbsp; &nbsp;Couldn't match expected type `Data.ByteString.Internal.ByteString'</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; against inferred type `Data.ByteString.Lazy.Internal.ByteString'</div><div>&nbsp;&nbsp; &nbsp;In the expression: showDigest . sha1</div><div>&nbsp;&nbsp; &nbsp;In a case alternative: "sha1" -> showDigest . sha1</div><div>&nbsp;&nbsp; &nbsp;In the expression:</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;case codec of {</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"md5" -> md5sum</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"sha1" -> showDigest . sha1</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_ -> error "Codec must be md5 or sha1 !" }</div><div><br></div><div><br></div><div>How can I both use md5sum and sha1 when one use a lazy ByteString end the other one does not ?</div><div><br></div><div>Thanks</div><div><br></div><div>E</div><div><br></div><div><br></div><div><br></div></div><div><br></div></div><br><div> <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>--</div><div>Emmanuel Delaborde</div><div>Web Technologist</div><div>Cimex<br>53-55 Scrutton Street, London UK, EC2A 4PJ<br>T: +44 (0)20 7324 7780<br>F: +44 (0)20 7324 7781<br><a href="http://www.cimex.com/">http://www.cimex.com</a></div></div></span></div></span> </div><br></body></html>
<pre>-----------------------------------------------------------------------------------------------

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@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.