package pidgin
Build not yet checkedInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9f05aa80a2867cc15fabbf6d52239567d2d3b386c611dc0467c27799526e5bfc
sha512=42ae7eefe12dfba69266a1e4a19a36c7e4000a30325d222cff8f95fafb011d886b455f3aef0553c4de40d0f7d23455fdbbcca9a273a7095ca6f9d6e999e7aba7
Description
Pidgin is a common language for dealing with serialization an deserialization of complex data structures
Added to opam-repository:
README
pidgin
The main idea is to present a minimal representation (very similar to that of JSON) and to provide:
- A DSL for describing arbitrary data structures in this language.
- Validation functions that operate on data described using this DSL
- A bidirectional conversion approach, imposing a cost due to the indirect nature of the generic format (though it is viable in many scenarios).
Pidgin does not statically preserve the type of expressions; instead, it hides them, which allows expressions written in this language to be treated as an untyped runtime representation of arbitrary OCaml values (enabling the derivation of pretty-printers and equality functions, for example).
History and Trivia
Pidgin is derived from the Yocaml.Data module (from the YOCaml project) and the Rensai validation model, which originated from Kohai.
The name "Pidgin", a grammatically simplified form of contact language that develops between two or more groups of people that do not have a language in common (Wikipedia), was suggested by Lorie Den Os.
A simple example
Here is a very short example that demonstrates how to serialize and deserialize Pidgin expressions:
module Gender = struct
type t =
| Male
| Female
| Other of string
let to_pidgin x =
Repr.string
(match x with
| Other s -> s
| Male -> "male"
| Female -> "female")
;;
let from_pidgin =
let open Check in
string
$ function
| "male" | "m" -> Male
| "female" | "f" -> Female
| other -> Other other
;;
endmodule Human = struct
type t =
{ nickname : string
; firstname : string option
; lastname : string option
; age : int option
; gender : Gender.t
}
let make ?firstname ?lastname ?age ~nickname ~gender () =
{ nickname; firstname; lastname; age; gender }
;;
let to_pidgin { nickname; firstname; lastname; age; gender } =
let open Repr in
record
[ "nickname", string nickname
; "firstname", option string firstname
; "lastname", option string lastname
; "age", option int age
; "gender", Gender.to_pidgin gender
]
;;
let from_pidgin =
let open Check in
record (fun fields ->
let+ nickname = req ~alt:[ "nick"; "pseudo" ] fields "nickname" string
and+ gender = req fields "gender" Gender.from_pidgin
and+ firstname = opt ~alt:[ "first_name" ] fields "firstname" string
and+ lastname = opt ~alt:[ "last_name"; "name" ] fields "lastname" string
and+ age = opt fields "age" int in
make ?firstname ?lastname ?age ~nickname ~gender ())
;;
end
Dev Dependencies (7)
-
odoc
with-doc -
ocaml-lsp-server
with-dev-setup -
merlin
with-dev-setup -
ocp-indent
with-dev-setup -
ocamlformat
with-dev-setup -
utop
with-dev-setup -
alcotest
with-test & >= "1.9.1"
Optional Dependencies
None
Conflicts
None
Build status
Results of building pidgin with each compiler on check.ci.ocaml.org, run of against opam-repository 8d8d144. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
This version is not in the latest run; the versions below are.
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure