[clean-list] Re: Strict lists kill me...

Peter Achten peter88@cs.kun.nl
Tue, 02 Dec 2003 13:41:33 +0100


At 12:07 2-12-03 +0100, Jerzy Karczmarczuk wrote:

>[..]You may imagine that in the case of sound the synchro- asynchro-
>issues are quite important. But sometimes the graph-reduction
>has its own ideas about the order of events. Look at the
>[fragment of the] following program:
>
>// ========================
>Start :: *World -> (*World,*File)
>Start wrld
>   # (console,wrld) = stdio wrld
>   # console = fwrites "beginning of first fragment\n" console
>   # (a,wrld)  = playWav "file1.wav" wrld
>   # console = fwrites "end of first fragment\n" console
>   # (b,wrld) = playWav "file2.wav" wrld
>   # console = fwrites "end of second fragment\n" console
>   = (wrld,console)
>// ========================
>[..]

The point is, as you state:

>My superficial understanding is that the lines which use console are chained
>independently of instructions which handle wrld, so there is - a priori - no
>intrinsic, explicitly visible relative order among them.

You have specified no relation between console and world; therefore any 
sequential interleaving order of console operations and world operations is 
a valid execution of this program. Strictness is of no help; what you need 
is data-dependency between console and world, for instance by closing the 
console immediately after writing to it. This will relate console and 
world. Then you obtain the following code:

Start wrld
   #    wrld  = toConsole "beginning of first fragment\n" wrld
   # (a,wrld) = playWav "file1.wav" wrld
   #    wrld  = toConsole "end of first fragment\n" wrld
   # (b,wrld) = playWav "file2.wav" wrld
   #    wrld  = toConsole "end of second fragment\n" wrld
   = wrld

toConsole :: String *World -> *World
toConsole str world
         = let (console,world`) = stdio world in snd (fclose (console <<< 
str) world`)

Regards,
Peter