(* 超来 -- The domain-specific language of remote computation The expressions of the language are generally executed by the server (although they certainly can be executed locally, depending on the implementation of the CHR signature) *) (* The syntax of Chourai Chourai is embedded in OCaml. Chourai expressions of the type 'a are represented as OCaml values of the type 'a chr. Eddy Westbrook pointed out 'a chr seems a co-monad *) module type CHR = sig type 'a chr (* Representation type *) (* Injection functions for local data: literals of Chourai *) val unit : unit chr val int : int -> int chr val bool : bool -> bool chr val string : string -> string chr (* Build the application *) val app : ('a -> 'b) chr -> 'a chr -> 'b chr (* Two-argument application *) val app2 : ('a -> 'b -> 'c) chr -> 'a chr -> 'b chr -> 'c chr (* Function constants *) val lt : (int -> int -> bool) chr (* less than *) (* Control structures Execute the (side-effecting) computation (second argument) only if the test (the first argument) is true. Return the value of the test. The presence of a thunk betrays the fact that Chourai is call-by-value after all. *) val guard : bool chr -> (unit -> 'a chr) -> bool chr (* Return the value of a Chourai expression Invoking force may initiate the remote computation if the value is not yet known. This is a partial function; it may throw exceptions due to communication and other failures *) val force : 'a chr -> 'a end (* The simplest test: factorial server: compute n! remotely *) module type CHRFact = sig include CHR val fact : (int -> int) chr (* function constant *) end (* The implementation of the signature: batch CHR *) module CHRBatch : CHR module BatchFact : CHRFact (* With the explicit chr type, so that new constants could be added *) module CHRBatchExt : CHR with type 'a chr = 'a Future.future_t ref