[Haskell-cafe] I love type declarations. :-)
Daniel Carrera
dcarrera at digitaldistribution.com
Fri May 6 04:27:39 EDT 2005
Hey,
Whooo hoo! I just finished my first non-trivial Haskell program. It's
the pseudo-random number generator from RC4. And if it weren't for type
declarations I'd still be bug-hunting.
I've been trying to get the PRNG to work for two days, but Hugs kept
wanting to use Integer where Int should be used, ugh. But while reading
a Haskell tutorial I came accross type declarations:
function :: Int -> Int -> [Int]
This solved all my problems! I added proper type declarations to
everything, and suddenly Hugs was happy. Type declarations also brought
other benefits:
1) I quickly spoted two bugs I hadn't hit yet.
2) I removed the fromIntegral() functions, making the code cleaner.
3) And my code is self-documented.
Before, when writing imperative code, I would add a comment for each
function describing its input and output. Now type declarations provide
that, so I merely describe what the function does. And type declarations
are better than a comment because Haskell helps me make sure that they
are right.
Go Haskell!
Cheers,
Daniel.
More information about the Haskell-Cafe
mailing list