c-cube / cconv

[dead] combinators for type conversion (serialization/deserialization) to/from several formats. See this blog post (outdated): http://cedeela.fr/universal-serialization-and-deserialization.html
https://c-cube.github.io/cconv/
BSD 2-Clause "Simplified" License
27 stars 3 forks source link

Does tuple support default value? #12

Closed tiensonqin closed 7 years ago

tiensonqin commented 7 years ago

I'm working on a package to convert edn to mermaid flowcharts, I have no experience on ocaml, what I want is remove the need to pass some optional elements.

You can see here: https://github.com/tiensonqin/edn_mermaid/blob/master/example/publisher.edn#L18

c-cube commented 7 years ago

There is no particular support for default values, no. Currently there is no support for edn either…

prepor commented 7 years ago

@c-cube basic support for edn is here ;)

type options = {
  text : string option [@default None];
  shape : string [@default "R"]
} [@@deriving cconv]

type edge = (string * string * options) [@@deriving cconv]

Edn_cconv.of_string_exn decode_edge "[:a :b {:shape \"RB\"}]"

- : string * string * options = ("a", "b", {text = None; shape = "RB"})

https://github.com/prepor/ocaml-edn/blob/master/src/edn_cconv.mli

c-cube commented 7 years ago

Oh, that's pretty neat.

tiensonqin commented 7 years ago

@prepor @c-cube Cool, thanks for both of your help!