Lazy Evaluation with Standard ML

Published at 2010-05-07T08:17:59+01:00

In contrast to Haskell, Standard SML does not use lazy evaluation by default but an eager evaluation.

https://en.wikipedia.org/wiki/Eager_evaluation

https://en.wikipedia.org/wiki/Lazy_evaluation

You can solve specific problems with lazy evaluation easier than with eager evaluation. For example, you might want to list the number Pi or another infinite list of something. With the help of lazy evaluation, each element of the list is calculated when it is accessed first, but not earlier.

Emulating lazy evaluation in SML

However, it is possible to emulate lazy evaluation in most eager evaluation languages. This is how it is done with Standard ML (with some play with an infinite list of natural number tuples filtering out 0 elements):

http://smlnj.org/

Real laziness with Haskell

As Haskell already uses lazy evaluation by default, there is no need to construct a new data type. Lists in Haskell are lazy by default. You will notice that the code is also much shorter and easier to understand than the SML version.

http://www.haskell.org/

E-Mail your comments to `paul@nospam.buetow.org` :-)

Back to the main site

Proxied content from gemini://foo.zone/gemfeed/2010-05-07-lazy-evaluation-with-standard-ml.gmi (external content)

Gemini request details:

Original URL
gemini://foo.zone/gemfeed/2010-05-07-lazy-evaluation-with-standard-ml.gmi
Status code
Success
Meta
text/gemini;
Proxied by
kineto

Be advised that no attempt was made to verify the remote SSL certificate.