
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.

On 5/6/05, Daniel Carrera
function :: Int -> Int -> [Int] Before, when writing imperative code, I would add a comment for each function describing its input and output. Now type declarations provide
What do you mean? In C++ one would write: vector<int> function(int a, int b) { ... } Type annotations are independent of functional/imperative style. (Although C++, the most used imperative language requires type annotations). -- regards, radu http://rgrig.blogspot.com/

Radu Grigore wrote:
vector<int> function(int a, int b) { ... }
You're assuming I use C++ :-) Yes, I fully realize that languages like C, C++ and others have this property, but they make up the complexity elsewhere. Unless I really need the speed, I write my programs in Ruby or a similar language, and /those/ don't have the property above. Cheers, Daniel.

On 5/6/05, Daniel Carrera
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!
Indeed, type annotations are very useful, at least for the "top-most" functions in your module (the rest of the functions are usually so simple that there's no need for them from a documentation standpoint, and if the top-most functions have correct types the compiler can usually infer the types of the other functions easily). /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862
participants (3)
-
Daniel Carrera
-
Radu Grigore
-
Sebastian Sylvan