Closed douglarek closed 8 years ago
AFAICT fieldslib seems to be only a library, you would need ppx_fields_conv (for ppx) or pa_fields_conv (for camlp4) to use it as an extension. The "modern" way would be the ppx version, just add ppx_fields_conv to the build-deps of your exe/lib and it should preprocess the file and compile it from obuild 0.1.8. If it doesn't please provide your test and open a ticket, I will fix the bug. It is also possible with camlp4 (a little bit more complicated but not much), however I couldn't install pa_fields_conv with ocaml 4.02.3 ...
@jeromemaloberti thanks for your quick reply;
this is my project :https://gist.github.com/douglarek/9e7915e847245b236890179af3d49209;
It failed:
File "src/main.ml", line 32, characters 6-10:
Error: Syntax error
Thank you. It is indeed a bug, I forgot to use the preprocessor when calling ocamldep to get the dependencies. I will fix it tonight.
Actually, I got it wrong. The problem is that you're using the camlp4 extension with ppx. You must replace "with fields" with "[@@deriving fields]" and it will work. You can see the example: https://github.com/janestreet/ppx_fields_conv/blob/master/example/test.ml
Thanks, I am a newbie to OCaml, but how can I use with fields
rather than [@@devering fields], I am reading Real world OCaml book.
@douglarek Why can't you just do [@@deriving fields]
? It should generate the same code for you.
@rgrinberg this is an example in book Real world OCaml, but it did not work with obuild
@douglarek post your project in a git repo somewhere
@rgrinberg Please follow https://gist.github.com/douglarek/9e7915e847245b236890179af3d49209
Sorry for the late answer. You can use pa_fields_conv ("with fields") by adding pa_fields_conv to the build-deps (you need to install it, of course) and by adding: pp: camlp4o in your target description. So: executable hello main: main.ml src-dir: src pp: camlp4o build-deps: core, pa_fields_conv
However, pa_fields_conv has been tagged deprecated, so maybe you should think about using ppx_fields_conv and replace "with fields" with "[@@deriving fields]" ...
@jeromemaloberti But I just tried [@@deriving fields]
, it works without ppx_fields_conv
preprocessing, maybe it is part of core
. And my OCaml version is 4.02.
Yes, and no. ppx are annotations, the code compile without the preprocessing, but no code was generated, so if you try to use the supposedly generated code, it will fail.
@jeromemaloberti thanks, it is very kind of you to answer so lubberly problem.
Take
filedslib
for example.