Library Apps.System

Require Import BinNums ExtrOcamlZBigInt FunctionApp String.

Inductive abortable {world t} :=
| started (abort : action world)
| done (_ : t).

Arguments abortable : clear implicits.

Definition stackAbortable {input world t} (xa : abortable world t) :=
  match xa with
    | started abortstarted (stackLift (input := input) abort)
    | done xdone x
  end.

Inductive httpStatus :=
| httpOk
| httpPreconditionFailed
| httpUnrecognizedCode.

Record httpResponse :=
  {
    httpResponseStatus : httpStatus;
    httpResponseStatusText : string;
    httpResponseProtocol : string;
    httpResponseHeader : list (string × string);
    httpResponseBody : string
  }.

Section systemActions.
  Context {input : Type}.
  Context {world : Type}.
  Record systemActions :=
    {
      consoleErr : stringaction world;
      consoleIn : (stringinput) → action world;
      consoleOut : stringaction world;
      exit : Naction world;
      getArgv : (list stringinput) → action world;
      getNanosecs : (Ninput) → action world;
      getRandomness : N → (stringinput) → action world;
      httpPOST : stringlist (string × string) → (abortable world httpResponseinput) → action world;
      setDebug : Naction world;
      sleepNanosecs : Ninputaction world
    }.
End systemActions.

Arguments systemActions : clear implicits.