type json mytype = Foo | Bar of int * int
(* just add "json" to the type declaration to create to
create the json_of_mytype and mytype_of_json functions *)
* list comprehensions, heredocs, string interpolation, lazy pattern matching, "do syntax" for monads (very much like Haskell's)...
Here's some OCaml code that relies on a rather large syntax extension of mine which allows you to generate (or verify) SQL schemas automatically and build composable queries using a typed relational algebra (the type system ensures that all queries are valid; if you change the schema and break some queries, the compiler will tell you what's wrong --- broken queries just don't compile):
TABLE user users
COLUMN id SERIAL AUTO PRIMARY KEY
COLUMN name VARCHAR(64) UNIQUE
COLUMN age INT NULLABLE INDEXED
COLUMN password VARCHAR(64)
END
TABLE comment comments
COLUMN id SERIAL AUTO PRIMARY KEY
COLUMN title TEXT
COLUMN text TEXT
COLUMN created_at TIMESTAMPZ
COLUMN author SERIAL FOREIGN(users, id)
END
let minors x = SELECT [User_age < (Some 18)] x
let pauls = SELECT [User_name LIKE "%Paul%"] users
let young_pauls = minors pauls
Yes, that's what I meant (you change the grammar, resulting in new syntax).
Some examples of what you can do with camlp4:
http://martin.jambon.free.fr/pa_memo.ml allows to define memoized functions very conveniently:
Automatic generation of* typed JSON marshallers (http://martin.jambon.free.fr/json-static.html)
* serialization with S-expressions (http://www.janestcapital.com/ocaml/)* pretty-printing, type-safe marshalling with structure-sharing, dynamic typing, equality... (http://code.google.com/p/deriving/)
* list comprehensions, heredocs, string interpolation, lazy pattern matching, "do syntax" for monads (very much like Haskell's)...
Here's some OCaml code that relies on a rather large syntax extension of mine which allows you to generate (or verify) SQL schemas automatically and build composable queries using a typed relational algebra (the type system ensures that all queries are valid; if you change the schema and break some queries, the compiler will tell you what's wrong --- broken queries just don't compile):
You can read more about this extension at http://eigenclass.org/hiki/typed-relational-algebra-in-OCaml