References in D

Russel Winder russel at winder.org.uk
Mon Sep 17 06:56:13 PDT 2012


On Mon, 2012-09-17 at 15:49 +0200, Timon Gehr wrote:
[…]
> In effect, everything is a non-null reference to mutable, but as
> mutation is constrained rather specifically, it is possible to reason
> about the behaviour of Haskell programs on a higher level of
> abstraction.
> 
>  > let fib n = if n<2 then n else fib (n-1) + fib (n-2)
>  > let x = fib 30
>  > let y = x
>  > let z = x
>  > y
> (delay)
> 832040
>  > z
> (no delay)
> 832040

This is just an artefact of Haskell being a lazy language: x is only
evaluated on demand; the lack of delay is due to the fact the value is
already computed.

Hopefully no-one actually uses that expression for calculating Fibonacci
series for real.

Are you sure the references are to mutable? I had understood Haskell to
be a single assignment to immutable values language.

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120917/a8e7d007/attachment.pgp>


More information about the Digitalmars-d mailing list