Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/MLRISC/library/susp.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/library/susp.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 412 - (view) (download)

1 : monnier 411 (*
2 :     * Force/delay
3 :     *
4 :     * -- Allen
5 :     *)
6 :    
7 : monnier 245 signature SUSPENSION =
8 :     sig
9 :     type 'a susp
10 :     val $$ : (unit -> 'a) -> 'a susp
11 :     val !! : 'a susp -> 'a
12 :     end
13 :    
14 :     structure Suspension :> SUSPENSION =
15 :     struct
16 :     datatype 'a thunk = VALUE of 'a | CLOSURE of unit -> 'a
17 :     type 'a susp = 'a thunk ref
18 :    
19 :     fun $$ e = ref(CLOSURE e)
20 :     fun !! (ref (VALUE v)) = v
21 :     | !! (r as ref(CLOSURE e)) =
22 :     let val v = e()
23 :     in r := VALUE v; v end
24 :     end
25 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0