package pidgio-unix

  1. Overview
  2. Docs

Module Pidgio_unix.MakeSource

Parameters

Signature

include Pidgio.Sigs.SERVER with type 'a t = 'a
Sourcetype 'a t = 'a

The main type of the server.

Sourcetype input

In Channel

Sourcetype output

Out Channel

Primavera Effects handlers

The server wrap a Primavera dependency injection on top of the given monad 'a t.

module Eff : Primavera.Sig.S1 with type 'a output = 'a t

Complete interface built on top of Req.S1.

Types

Sourcetype ('a, 'handler) eff = ('a, 'handler) Eff.t

Hold a value of type 'a that needs 'handler to be performed.

Sourcetype pidgin = Pidgin.Repr.t

Service should return a pidgin expression.

Sourcetype 'a args = 'a Highway.Args.t

args type describes a heterogeneous list used to generate links associated with a route. It can also serve as a controller parameter.

Sourcetype 'a hole = 'a Highway.Hole.t

hole describes an arbitrary value that can be serialized or deserialized. They are used to describe route patterns that introduce variables.

Sourcetype ('a, 'b) pattern = ('a, 'b) Highway.Pattern.t

pattern is a path fragment. It can be either a constant value (using the s function) or a placeholder that introduces a variable (using hole) into the path.

Sourcetype ('a, 'b) path = ('a, 'b) Highway.Path.t

path is a heterogeneous list of patterns (which introduces holes in the final type signature).

Sourcetype 'a param = 'a Pidgin.Prism.t

param is a prism for dealing with route parameters.

Sourcetype ('hole, 'param) route = ('hole, 'param) Pidgio.Route.t

route is a combination of a path and param.

Sourcetype 'param request = 'param Pidgio.Request.t

request materialize the incomming request.

Sourcetype 'handler service

Describes a service capable of producing 'handler'-type effects for use in a Primavera context.

Utils

Sourceval return : 'a -> ('a, 'handler) eff

return x wrap x into the eff context.

Sourceval error : code:int -> ?message:string -> unit -> Pidgio.Error.t

error ~code ?message () build a custom error. See Error.custom.

Describing patterns

Literal Pattern

Sourceval s : string -> ('a, 'a) pattern

s value describes a Literal pattern, a constant that does not introduce a variable into a pattern.

Hole Pattern

You can define your own patterns using Hole and Pattern.

Sourceval string : (string -> 'a, 'a) pattern

Describes a pattern that introduces a variable of type string.

Sourceval int : (int -> 'a, 'a) pattern

Describes a pattern that introduces a variable of type int.

Sourceval float : (float -> 'a, 'a) pattern

Describes a pattern that introduces a variable of type float.

Sourceval char : (char -> 'a, 'a) pattern

Describes a pattern that introduces a variable of type char.

Sourceval bool : (bool -> 'a, 'a) pattern

Describes a pattern that introduces a variable of type bool.

Sourceval opt : ?empty:string -> 'a hole -> ('a option -> 'b, 'b) pattern

Describes a potentially empty hole. It use empty to define if a value is present or not in a route path.

Param definition

Sourceval param : conv:'a Pidgin.Repr.conv -> check:'a Pidgin.Check.t -> 'a param

Build a prism for validating/producing parameters. You can build complicated param prisms using this function.

Sourceval ignore_param : unit param

Ignore param

Sourceval string_param : string param

Describe a param for string.

Sourceval int_param : int param

Describe a param for int.

Sourceval float_param : float param

Describe a param for float.

Sourceval bool_param : bool param

Describe a param for bool.

Sourceval char_param : char param

Describe a param for char.

Sourceval list_param : 'a param -> 'a list param

Describe a param for list.

Sourceval opt_param : 'a param -> 'a option param

Describe a param for option.

Sourceval pair_param : 'a param -> 'b param -> ('a * 'b) param

Describe a param for pair.

Building routes

Sourceval route : ('args, Highway.Void.t) path -> 'param param -> ('args, 'param) route

route path param_check wrap a path and a Pidgin.Check.t for building a route.

Sourceval make_request_string : ?id:int -> ('args, 'param) route -> 'args args -> 'param -> string

make_request_string ?id route args param constructs the string that corresponds to the query for the given route.

Building services

Sourceval notify : ?precondition:(pidgin request -> bool) -> ?postcondition:('a args -> 'param -> 'param request -> bool) -> ('a, 'param) route -> ('a args -> 'param -> 'param request -> (unit, 'handler) eff) -> 'handler service

notify Describes a straight service that does not output anything.

Sourceval straight : ?precondition:(pidgin request -> bool) -> ?postcondition:('a args -> 'param -> 'param request -> bool) -> to_pidgin:('result -> pidgin) -> ('a, 'param) route -> ('a args -> 'param -> 'param request -> ('result, 'handler) eff) -> 'handler service

straight Describes a service that is not supposed to fail.

Sourceval failable : ?precondition:(pidgin request -> bool) -> ?postcondition:('a args -> 'param -> 'param request -> bool) -> to_pidgin:('result -> pidgin) -> to_error:('error -> Pidgio.Error.t) -> ('a, 'param) route -> ('a args -> 'param -> 'param request -> (('result, 'error) result, 'handler) eff) -> 'handler service

failable Describes a service that can fail.

Infix

Some infix operators.

module Infix : sig ... end
Sourceval (&) : ('args, Highway.Void.t) path -> 'param param -> ('args, 'param) route

path & prism is route path prism.

Sourceval (~&) : ('a, Highway.Void.t) path -> ('a, unit) route

~&path is route path ignore_param.

include module type of Eff.Infix
val (<$>) : ('a -> 'b) -> ('a, 'handler) Eff.t -> ('b, 'handler) Eff.t

f <$> x is map f x (infix version of map)

val (<$) : 'a -> ('b, 'handler) Eff.t -> ('a, 'handler) Eff.t

a <$ x is replace a x (infix version of replace)

val ($>) : ('a, 'handler) Eff.t -> 'b -> ('b, 'handler) Eff.t

x $> a is replace a x (infix (flipped) version of replace)

val (<*>) : ('a -> 'b, 'handler) Eff.t -> ('a, 'handler) Eff.t -> ('b, 'handler) Eff.t

f <*> x is apply f x (infix version of apply)

val (<&>) : ('a, 'handler) Eff.t -> ('b, 'handler) Eff.t -> ('a * 'b, 'handler) Eff.t

a <&> b is zip a b (infix version of zip)

val (<*) : ('a, 'handler) Eff.t -> ('b, 'handler) Eff.t -> ('a, 'handler) Eff.t

a <* b Perform a and b but discard b.

val (*>) : ('a, 'handler) Eff.t -> ('b, 'handler) Eff.t -> ('b, 'handler) Eff.t

a *> b Perform a and b but discard a.

val (<<) : ('a, 'handler) Eff.t -> ('b, 'handler) Eff.t -> ('a, 'handler) Eff.t

a << b Sequentially perform a following by b but discard b.

val (>>) : ('a, 'handler) Eff.t -> ('b, 'handler) Eff.t -> ('b, 'handler) Eff.t

a >> b Sequentially perform a following by b but discard a.

val (>>=) : ('a, 'handler) Eff.t -> ('a -> ('b, 'handler) Eff.t) -> ('b, 'handler) Eff.t

m >>= f is bind m f (infix version of bind)

val (=<<) : ('a -> ('b, 'handler) Eff.t) -> ('a, 'handler) Eff.t -> ('b, 'handler) Eff.t

f =<< m is bind m f (infix (flipped) version of bind)

val (<=<) : ('a -> ('b, 'handler) Eff.t) -> ('c -> ('a, 'handler) Eff.t) -> 'c -> ('b, 'handler) Eff.t

f <=< g is compose f g (infix version of compose)

val (>=>) : ('a -> ('b, 'handler) Eff.t) -> ('b -> ('c, 'handler) Eff.t) -> 'a -> ('c, 'handler) Eff.t

f >=> g is compose g f (infix (flipped) version of compose)

Bindings Operators

module Syntax = Eff.Syntax
val (let+) : ('a, 'handler) Eff.t -> ('a -> 'b) -> ('b, 'handler) Eff.t

let+ x = m in f x is map (fun x -> f x) m.

(binding version of map)

val (and+) : ('a, 'handler) Eff.t -> ('b, 'handler) Eff.t -> ('a * 'b, 'handler) Eff.t

let+ x = m and+ y = n in f x y is map (fun (x, y) -> f x y) (zip m n).

(binding version of zip)

val (let*) : ('a, 'handler) Eff.t -> ('a -> ('b, 'handler) Eff.t) -> ('b, 'handler) Eff.t

let* x = m in f x is bind m (fun x -> f x).

(binding version of bind)

val (and*) : ('a, 'handler) Eff.t -> ('b, 'handler) Eff.t -> ('a * 'b, 'handler) Eff.t

let* x = m and* y = n in f x y is bind (zip m n) (fun (x, y) -> f x y).

(binding version of zip)

Sourceval run : handler:'handler -> 'handler service list -> unit

run ~handler services launch a Pidgio server for the given list of services under the dedicated handler.