[Haskell-cafe] strict version of Haskell - does it exist?

Ertugrul Söylemez es at ertes.de
Mon Jan 30 15:25:09 CET 2012

Alexander Bernauer <alex-haskell at copton.net> wrote:

> On Sun, Jan 29, 2012 at 11:25:09PM +0100, Ertugrul Söylemez wrote:
> > First of all, /learning/ to optimize Haskell can be difficult.  The
> > optimizing itself is actually fairly easy in my experience, once you
> > understand how the language works.
> Given the fact that you have obviously mastered the learning part of
> this, do you have any recommendations on what to read or on how to
> proceed in order to learn how to optimize Haskell code?
> I can imagine, it's not only about understanding the language itself,
> but also about understanding how your compiler and its switches work,
> being able to find the hot spots in your code, being able to measure
> the effects of your changes, developing a good sense for the
> tradeoffs, etc.
> So far, I have only stumpled upon chapter 25 of Real World Haskell.
> Anything else you might recommend?

That's the tricky part about this.  Unfortunately the monad tutorial
fallacy [1] applies here.  At some point it makes click and suddenly you
see all the data dependencies.  If you were schizophrenic, you would
probably see little arrows all over your code.

What helped me a bit was to read the Wikibooks page about Haskell's
denotational semantics [2], but other than that I pretty much learned it
by myself.

In any case it's helpful to use 'seq' explicitly instead of bang
patterns.  Personally I never use bang patterns, but always use seq,
strict patterns or guards with strict functions.  Example:

    add :: Integer -> Integer -> Integer
    add x 0 = x
    add x y = (add $! succ x) (pred y)

Here the pattern forces the second argument, so there is no need to
force it yourself.  However, nothing forces the first argument, so it
needs to be forced manually, in this case by using ($!).

[1]: <http://byorgey.wordpress.com/2009/01/12/

[2]: <http://en.wikibooks.org/wiki/Haskell/Denotational_semantics>


nightmare = unsafePerformIO (getWrongWife >>= sex)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120130/5b40f62b/attachment.pgp>

More information about the Haskell-Cafe mailing list