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

cconv.ppx for tuples #1

Closed edwintorok closed 9 years ago

edwintorok commented 9 years ago

I get an error when using cconv.ppx (installed-version: 0.3 [4.02.1]):

type t = string * int [@@deriving cconv]
ocamlfind ocamlc -package cconv.ppx x.ml -dsource
type t = (string* int)[@@deriving cconv]
let encode: _ CConv.Encode.encoder =
  CConv.Encode.tuple
    (fun (arg0,arg1)  ->
       [CConv.Encode.string.CConv.Encode.emit into arg0;
       CConv.Encode.int.CConv.Encode.emit into arg1])
and decode: _ CConv.Decode.decoder =
  let open CConv.Decode in
    tuple
      {
        tuple_accept =
          (fun src  ->
             fun args  ->
               match args with
               | arg0::arg1::[] ->
                   ((CConv.Decode.apply src CConv.Decode.string arg0),
                     (CConv.Decode.apply src CConv.Decode.int arg1))
               | _ -> CConv.report_error "expected %d-ary tuple" 2)
      }
File "x.ml", line 1, characters 0-40:
Error: This expression should not be a function, the expected type is
'a CConv.Encode.tuple_encoder
c-cube commented 9 years ago

Right, let me fix it.

c-cube commented 9 years ago

You might want to opam pin add -k git cconv https://github.com/c-cube/cconv.git until I make a bugfix release (soon). I must add more tests.

edwintorok commented 9 years ago

Thanks for the quick fix