1. camlspotter
  2. pa_fun_fields




Fields as functions via P4.

You can use the following syntaxes:

  • (.l) == fun x -> x.l
  • (#m) == fun x -> x#m
  • (.[e]) == fun x -> x.[e]
  • (.[]) == fun x i -> x.[i]
  • (.(e)) == fun x -> x.(e)
  • (.()) == fun x i -> x.(i)

How to build

$ cp OMakeroot.in OMakeroot
$ omake
$ omake install

How to test

$ omake test


$ omake top_test

to test it interactively.

How to use

$ ocamlfind ocamlc -syntax camlp4o -package pa_fun_fields -c test_pa_fun_fields.ml

What's the differece from Fieldslib

Fieldslib is also a P4 syntax extension but pa_fun_fields and Fieldslib work differently.

Fieldslib auto-generate field access named function. If you have type t = { x : int } with fields, you got a pure OCaml function x : t -> int.

  • Pros: You only see its syntax modification at the type definition.
  • Cons: The field access functions are only available for the type definitions with with fields.

pa_fun_fields does not create a normal function like Fieldslib. It just provides a syntax sugar of field accesses.

  • Pros: It does not generate code and works for any types.
  • Cons: It is not a pure OCaml function but a wierd syntax.

Bug report

Please submit at https://bitbucket.org/camlspotter/pa_fun_fields/admin/issues