package rpclib

  1. Overview
  2. Docs

This module generates Client modules from RPC declarations.

The implementation of the module as a whole is unused. However, the namespace comes from the interface description, and hence calling implement is important.

The result of declaring a function of type 'a (where for example 'a might be (int -> string -> (bool, err) result)), is a function that takes an rpc function, which might send the RPC across the network, and returns a function of type 'a, in this case (int -> string -> (bool, err) result).

Our functions return a Result.t type, which contains the result of the Rpc, which might be an error message indicating a problem happening on the remote end.



include RPC with type implementation = client_implementation and type 'a res = T.rpcfn -> 'a and type ('a, 'b) comp = ('a, 'b) T.resultb
type implementation = client_implementation

The implementation is dependent on the module, and represents the 'result' of the entire module. For example, in the Server module, the `implementation` is the server function, with type -> Rpc.response.

For the Client module, the individual declarations are used to perform the RPCs, and the 'implementation' type is simply unit.

To actually construct the implementation, an interface description must be provided

type 'a res = T.rpcfn -> 'a

'a res is the result type of declaring a function. For example, the Client module, given an (int -> int -> int) fn, will return a function of type 'a - in this case, (int -> int -> int)

type ('a, 'b) comp = ('a, 'b) T.resultb

This is for inserting a type in between the function application and its result. For example, this could be an Lwt.t, meaning that the result of a function application is a thread

type _ fn

The GADT specifying the type of the RPC

val (@->) : 'a Param.t -> 'b fn -> ('a -> 'b) fn

This infix operator is for constructing function types

val noargs : 'b fn -> (unit -> 'b) fn

Require a unit argument in OCaml without sending a parameter. Useful for methods that take no arguments.

val returning : 'a Param.t -> 'b Error.t -> ('a, 'b) comp fn

This defines the return type of an RPC

val declare : string -> string list -> 'a fn -> 'a res

declare name description typ is how an RPC is declared to the module implementing the functionality. The return type is dependent upon the module being used

val declare_notification : string -> string list -> 'a fn -> 'a res

declare_notification name description typ is mostly the same as declare, only that it allows support from JSON-RPC notifications.

val make_strict : unit -> unit

This is irreversible, once used the client will fail in case of Rpc failure ( instead of returning the error (M.return (Error ...)).


Innovation. Community. Security.