Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Dynamic Programming in Haskell (Heinrich Apfelmus)
----------------------------------------------------------------------
Message: 1
Date: Thu, 08 Jul 2010 10:30:17 +0200
From: Heinrich Apfelmus <[email protected]>
Subject: [Haskell-beginners] Re: Dynamic Programming in Haskell
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
Daniel Fischer wrote:
> On Wednesday 07 July 2010 18:40:07, Ali Razavi wrote:
>> Thanks a lot for your through and informative response. Your solution is
>> well-structured and pellucid. The only part I don't understand is in the
>> definition of Parens:
>>
>> data Parens = Mul !Cost Dimension Parens Parens
>>
>> | Matrix Dimension deriving (Show)
>>
>> What is the exclamation mark in !Cost, and what does it signify?
>
> It's a strictness annotation and signifies that a Mul-value must always be
> constructed with an evaluated Int and not with a reference to a
> computation.
I.e. a small optimization. It is very common to use this for cached
values at the branches of a tree.
The idea is that we would like to evaluate the cost early; after all,
lazy evaluation might build up computations like
Mul (((0 + 0 + 10*100*5) + 0 + 10*5*50) + 0 + 10*50*1) ...
and only evaluate them at the very end. This might give a stack overflow
when the expression is large, but since we know that the cost is needed,
we can evaluate it right away. (This is like foldl vs foldl' )
Regards,
Heinrich Apfelmus
--
http://apfelmus.nfshost.com
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 25, Issue 26
*****************************************