src/HOL/Import/susp.ML
author urbanc
Wed, 11 Jan 2006 17:10:11 +0100
changeset 18655 73cebafb9a89
parent 17802 f3b1ca16cebd
permissions -rw-r--r--
merged the silly lemmas into the eqvt proof of subtype

(*  Title:      HOL/Import/susp.ML
    ID:         $Id$
    Author:     Sebastian Skalberg, TU Muenchen

Delayed evaluation.
*)

signature SUSP =
sig

type 'a susp

val force : 'a susp -> 'a
val delay : (unit -> 'a) -> 'a susp
val value : 'a -> 'a susp

end

structure Susp :> SUSP =
struct

datatype 'a suspVal
  = Value of 'a
  | Delay of unit -> 'a

type 'a susp = 'a suspVal ref

fun force (ref (Value v)) = v
  | force (r as ref (Delay f)) =
    let
	val v = f ()
    in
	r := Value v;
	v
    end

fun delay f = ref (Delay f)

fun value v = ref (Value v)

end