Haskell: Simple 8-bit checksum implementation

In my continued quest to use Haskell for everything, I wrote this today: it creates a simple checksum for a Nokia CIMD2 communications driver that I am writing in PHP.

I needed a second source of verification that my PHP code was doing the right thing so I banged this out in fifteen minutes, warts and all. It may not be "perfect" Haskell but for me to get this done in fifteen minutes has been a real confidence booster, both in reading the error messages and understanding what I am doing.

The code is available on this page to as I seem to have serious issues with Drupal and SyntaxHighlighter not working on large amounts of code, it refuses to save. I'd love to know how to fix that! Anybody??

The command line is not case sensitive as I didn't need it but a quick composition of "map toLower" would have done it for me. Typical command line:

$ ./cc STX 0 1 : 0 0 1 TAB 0 1 0 : f r e d TAB 0 1 1 : p a s s w o r d TAB
Checksum: f4 Hex, Decimal: 244

My PHP code outputs the command line on my test page so all I do is cut and paste my PHP output to the bash shell, hit RETURN and I get me checksum.

Haskell rocks and today I was very pleased to find that the "digitToInt" function automatically caters for 0-9, A-F and a-f. Sweet.

Content Tags: 

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <pre> <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or class="OPTIONS" [title="the title"].
  • Lines and paragraphs break automatically.

Full HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or class="OPTIONS" [title="the title"].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.