Haskell: Simple 8-bit checksum implementation
Published by emacstheviking on Thu, 06/23/2011 - 15:49
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.
Add new comment