Reply to comment

Real World Haskell: Chapter 5

Chapter 5 of Real World Haskell covers the creation of our first Haskell module. The chapter seems to come prematurely from my perspective. I am not yet concerned about making a module while I'm still trying to understand the language.

One thing that did catch my attention is the Prelude.undefined special value which allows for easy creation of stub code:

-- This compiles but causes a runtime error if you try to execute it
text :: String -> Doc
text str = undefined

Bitwise Functions
We also learn in Chapter 5 that the bitwise manipulations we have come to take for granted in C, C++ and similar languages is now a library module. This is the first point at which I can see an obvious point where C++ would make more succinct and readable code than Haskell.

import Data.Bits
0x10000 `shiftR` 4 :: Int
7 .&. 2 :: Int

int i = 0x10000 >> 4;
int j = 7 & 2;

It seems clear to me that if your code consists of mainly bit manipulations, C++ or C might be the logical choice.

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.
1 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.