Although ML is a strict language, Alice provides full support for lazy evaluation. A lazy computation is created through the predefined procedure

	val byneed: (unit -> 'a) -> 'a 
  

It takes a procedure and returns a handle for its result (a so-called future). The procedure will be evaluated when some operation first tries to access this result.

If the procedure passed to byneed terminates with an exception e, any attempt to access the result value will cause an exception Future(e) to be raised.

Note that by-need evaluation is just one aspect of Alice's future mechanism.

The following code lazily generates an infinite list of integers:

	fun enumFrom n = byneed(fn() => n :: enumFrom(n+1))

	val ns = enumFrom 0
  

Printing this list will produce infinite output:

	List.app (fn n => print(Int.toString n ^ "\n")) ns
  

Here is lazy variant of map that can deal with infinite lists:

	fun mapl f   []    = nil
	  | mapl f (x::xs) = byneed(fn() => f x :: mapl f xs)