[Haskell-cafe] data type declaration

Andrew Coppin andrewcoppin at btinternet.com
Sun Jul 25 10:48:10 EDT 2010

Patrick Browne wrote:
> Andrew,
> Thanks for your detailed feedback, it is a great help.

Well, I like to be helpful.

> I appreciate that the code does not do anything useful, nor is it an
> appropriate way to write Haskell, but it does help me
> understand language constructs.

Personally, I find it easier to understand things when they do something 
meaningful, but sure.

> I am studying the Haskell type class system as part of a language
> comparison. I am trying to exercise and understand the constructs rather
> than develop a meaningful application.

The best way to understand Haskell is... to completely forget everything 
you already know, and start again from scratch. ;-) Still, I gather 
that's not the point of this particular exercise.

Since you're interested in comparisons... A method is simply a way of 
giving the same name to several different functions, and have the 
compiler pick the correct one based on the argument types. That's what 
methods do in OOP, and it's what they do in Haskell too. The notable 
difference is that in Haskell, all types are known at compile-time. 
(Unless you turn on certain extra non-standard language features...)

The other point worth realising is that since Haskell has first-class 
functions, you don't "need" classes quite so much. (E.g., Java has the 
Runnable interface so that the JVM can call an object's run() method. In 
Haskell, you just say forkIO and pass it the function to execute. 
Similar deal for GUI callbacks and so forth.)

More information about the Haskell-Cafe mailing list