val client (c: Duplex.chan pingpong)
    : SteelT unit (Duplex.endpoint c pingpong) (fun _ -> Duplex.endpoint c Protocol.done)
val client (c: Duplex.chan pingpong)
    : SteelT unit (Duplex.endpoint c pingpong) (fun _ -> Duplex.endpoint c Protocol.done)
let client (c:Duplex.chan pingpong)
  : SteelT unit
           (Duplex.endpoint c pingpong)
           (fun _ -> Duplex.endpoint c Protocol.done)
  = // In this implementation, the client first sends the (arbitrarily chosen) integer 17
    Duplex.send c 17;
    let y = Duplex.recv c in
    // The protocol specifies that the integer received is greater than the one sent.
    // This fact is available in the context and can be asserted.
    assert (y > 17);
    // To end the protocol, we return unit
    ()
(*
   Copyright 2020 Microsoft Research

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*)

module PingPong
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
open Steel.Channel.Protocol
module Duplex = Steel.Channel.Duplex
module Protocol = Steel.Channel.Protocol

(** Specification and implementation of a pingpong protocol *)

/// Specification of a pingpong protocol.
/// The protocol consists of two messages.
/// A client first sends an integer on a channel.
/// It then receives an integer that is ensured to be strictly greater than the one she sent
/// The protocol then terminates by returning unit (done)
let pingpong : Duplex.prot =
  x <-- Protocol.send int;
  y <-- Protocol.recv (y:int{y > x});
  Protocol.done

/// An implementation of the pingpong protocol specified above.
/// The client takes as an argument a channel that satisfies the pingpong protocol
/// Additionally, it requires the separation logic assertion `endpoint c pingpong`
/// that indicates ownership of an endpoint for channel c, and that the protocol did not
/// start yet.
/// After execution, the postcondition specifies ownership of an endpoint for channel c,
/
Steel.Primitive.ForkJoin.fsti.checked Steel.Memory.fsti.checked Steel.Effect.Atomic.fsti.checked Steel.Effect.fsti.checked Steel.Channel.Protocol.fst.checked Steel.Channel.Duplex.fsti.checked prims.fst.checked FStar.Pervasives.fsti.checked FStar.List.Tot.Base.fst.checked
PingPong.fst
c: Steel.Channel.Duplex.chan PingPong.pingpong -> Steel.Effect.SteelT Prims.unit
Steel.Channel.Duplex.chan PingPong.pingpong Prims.unit Prims._assert Prims.b2t Prims.op_GreaterThan Steel.Channel.Protocol.msg_t Steel.Channel.Protocol.step Steel.Channel.Duplex.recv Steel.Channel.Duplex.send Steel.Channel.Duplex.endpoint Steel.Channel.Protocol.done Steel.Effect.Common.vprop
let client (c: Duplex.chan pingpong)
    : SteelT unit (Duplex.endpoint c pingpong) (fun _ -> Duplex.endpoint c Protocol.done) =
  
Duplex.send c 17;
let y = Duplex.recv c in
assert (y > 17);
()