Type-classes for mirage applications
OCaml Makefile
Latest commit de61028 Oct 3, 2016 @samoht samoht committed on GitHub Merge pull request #11 from djs55/LICENSE
Add LICENSE (ISC, matching headers)
Permalink
Failed to load latest commit information.
lib Update tc.mli Mar 12, 2015
lib_test
.travis.yml Update to latest .travis.yml Oct 31, 2014
CHANGES
LICENSE
Makefile
README.md Update README Dec 18, 2014
_oasis
_tags
configure
myocamlbuild.ml
opam
setup.ml Fix Tc.List.equal Dec 12, 2014

README.md

Mirage type-classes

A set of functors and combinators to convert to and from and JSON values and Cstruct buffers.

# require "tc";;

# Tc.show Tc.string "Hello world!";;
- : string = "[\"Hello world!\"]"

# Tc.to_json (Tc.pair Tc.int Tc.string) (3, "foo");;
- : Ezjsonm.value = `A [`Float 3.; `String "foo"]

A slightly more complex example, using autogen code instead of functor composition:

# require "tc";;

# type t = { foo: int; bar: string list };;

# let t =
    let module M = Tc.Pair (Tc.Int) (Tc.List(Tc.String)) in
    let to_t (foo, bar) = { foo; bar} and of_t {foo; bar} = (foo, bar) in
    Tc.biject (module M) to_t of_t;;

# Tc.show t { foo = 3; bar = [ "hello"; "world" ] }
- : string = "[3,[\"hello\",\"world\"]]"

# let j = Tc.to_json t { foo = 3; bar = [ "hello"; "world" ] }
- : Ezjsonm.value = `A [`Float 3.; `A [`String "hello"; `String "world"]]

# Tc.write_string Tc.string "hello world";;
- : string = "\011hello world"