Reply to comment

Real World Haskell: Chapters 1-2

Chapter 1 of Real World Haskell covers the most basic aspects of the language, such as common operators and operator precedence and gives some overviews of aspects of the language.

Chapter 2 discusses the type system. What stands out to me the most is that many of the claims that are made about the advantages of statically and strongly typed languages also applies to C++. The following excerpt illustrates my point:

Haskell's combination of strong and static typing makes it impossible for type errors to occur at runtime. While this means that we need to do a little more thinking “up front”, it also eliminates many simple errors that can otherwise be devilishly hard to find. It's a truism within the Haskell community that once code compiles, it's more likely to work correctly than in other languages. (Perhaps a more realistic way of putting this is that Haskell code often has fewer trivial bugs.)
...
In Haskell, the compiler proves the absence of type errors for us: a Haskell program that compiles will not suffer from type errors when it runs. Refactoring is usually a matter of moving code around, then recompiling and tidying up a few times until the compiler gives us the “all clear”.

Type Inference
However, Haskell says that it can infer types more often than not, making type declarations unnecessary. This reads as if every function call is equivalent to a C++ template.

Tuples
The Haskell notion of tuples seems to be very similar to that of boost::tuple, but cleaner as it is built into the language.

C++ example:

//Without the new "auto" type, coming in C++0x
boost::tuple<int, std::string, float> t = boost::make_tuple(5, "Hello", 2.3);
 
//The above is a bit cumbersome, and will be cleaned up with the auto tupe
auto t = boost::make_tuple(5, "Hello", 2.3);

Haskell, which is clearly cleaner:

t = (5, "Hello", 2.3);

Parametric Polymorphism
Haskell's parametric polymorphism seems to be strongly related to C++ function templates, but we'll hopefully get into that more later.

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You may post PHP code. You should include <?php ?> tags.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <cpp>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • Images can be added to this post.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
3 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.