anchor.diff:      Async.setMain ctx
       onEvent.RemoveHandler handler
   
  +/// Represents an immutable ToDo item.
   type Item = {
       IsCompleted: bool
       Header: string
     }
   
  +/// Module for generating unique ids.
   module Id =
     let mutable private id = 0L
  +
  +  /// Returns a new unique id.
     let next () = Interlocked.Increment &id
   
   [<STAThread; EntryPoint>]
   let main argv =
  +  /// The main window.
     let main = ToDo.UI.MainWindow ()
   
  +  // This makes it so that the stream wiring code is run after the main
  +  // synchronization context has been created.
     setupWhen main.Activated |>> fun () ->
   
  +      /// Serialized variable that holds the immutable model.  In this example
  +      /// it doesn't really make any difference, but the use of a serialized
  +      /// stream variable makes it easy to make sure that updates to the
  +      /// variable appear as atomic.
         let modelMVar = Stream.MVar.create Map.empty
   
  +      /// Functionally updates a ToDo item in the given model.
         let updateItem id f model =
           match Map.tryFind id model with
            | None -> model
            | Some item -> Map.add id (f item) model
   
  +      // This adds new ToDo items in response to Enter key presses on the
  +      // EnterHeader text box.
         Stream.ofObservableOnMain main.EnterHeader.KeyUp
         |> Stream.filterFun (fun evt -> evt.Key = Key.Enter)
         |> Stream.chooseJob (fun _ -> onMain {
  
positive.code:       |> Stream.subscribeJob (fun allCompleted -> onMain {
           main.CompleteAll.IsChecked <- Nullable<bool> allCompleted })
  
        Stream.ofObservableOnMain main.CompleteAll.Click
        |> Stream.subscribeJob (fun _ ->
           onMain { return main.CompleteAll.IsChecked.Value } >>= fun isCompleted ->
  
negative.code:            |> Seq.iter (fun bn' -> bn'.IsEnabled <- bn <> bn')
             return pred })
  
        /// Creates a control for a ToDo item.
        let newControl id item =
          let control = ToDo.UI.ItemControl ()
  
          // These statements copy the values from the item to the controls.
          control.IsCompleted.IsChecked <- Nullable<bool> item.IsCompleted
          control.Header.Text <- item.Header
          control.Header.FontStyle <-
            if item.IsCompleted then FontStyles.Italic else FontStyles.Normal
  
          // This updates the underlying item in response to a click on the
          // completed check box.
          Stream.ofObservableOnMain control.IsCompleted.Click
          |> Stream.subscribeJob (fun _ -> onMain {
             let isCompleted = control.IsCompleted.IsChecked.Value
  