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. Laziness, automatic memoization and arrays (Oscar Picasso)
2. Re: Laziness, automatic memoization and arrays (Brent Yorgey)
3. Re: Laziness, automatic memoization and arrays (Daniel Fischer)
----------------------------------------------------------------------
Message: 1
Date: Sat, 27 Aug 2011 19:03:00 -0400
From: Oscar Picasso <[email protected]>
Subject: [Haskell-beginners] Laziness, automatic memoization and
arrays
To: [email protected]
Message-ID:
<capkmfpmgmql_0ugorzbgbg9fhqupq_tc6hq36rzd+ppshoc...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Hi,
I have a very simple question about laziness, memoization and arrays.
If I have:
import Data.Array
a = listArray (1,10) $ map (\x -> (x*x)) [1..10]
main = do
print c ! 4
print c ! 4
print c ! 4
Can we assume that the operation 4 * 4 is evaluated only once, when
first calling print c ! 4 in the main method?
Oscar
------------------------------
Message: 2
Date: Sat, 27 Aug 2011 19:12:01 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Laziness, automatic memoization and
arrays
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Sat, Aug 27, 2011 at 07:03:00PM -0400, Oscar Picasso wrote:
> Hi,
>
> I have a very simple question about laziness, memoization and arrays.
> If I have:
>
> import Data.Array
>
> a = listArray (1,10) $ map (\x -> (x*x)) [1..10]
>
> main = do
> print c ! 4
> print c ! 4
> print c ! 4
>
>
> Can we assume that the operation 4 * 4 is evaluated only once, when
> first calling print c ! 4 in the main method?
Yes. Any value with a name (such as c in your example) will only be
evaluated once, no matter how many times you refer to it.
-Brent
------------------------------
Message: 3
Date: Sun, 28 Aug 2011 01:13:43 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Laziness, automatic memoization and
arrays
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="iso-8859-1"
On Sunday 28 August 2011, 01:03:00, Oscar Picasso wrote:
> Hi,
>
> I have a very simple question about laziness, memoization and arrays.
> If I have:
>
> import Data.Array
>
> a = listArray (1,10) $ map (\x -> (x*x)) [1..10]
>
> main = do
> print c ! 4
> print c ! 4
> print c ! 4
Needs parentheses,
print (c ! 4)
Without, it parses `(print c) ! 4' since function application binds tighter
than infix operators.
>
>
> Can we assume that the operation 4 * 4 is evaluated only once, when
> first calling print c ! 4 in the main method?
Yes. Although technically an implementation is allowed to recompute the
value, no serious implementation will.
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 38, Issue 45
*****************************************