14

I don't know how to accomplish this in general, but I'll ask about one instance in particular for clarity:

Sexplib looks interesting to me. I want to play around with it. I've downloaded it, installed it just fine (I'm pretty sure, anyway), etc. I want to use the "with sexp" syntax extension in a toplevel. How would I go about doing this? All the examples I've found of its use assume you already know how to make the toplevel and/or compile with the syntax extensions.

My best shot at it was something like this:

ocamlmktop -I +site-lib/sexplib -pp "camlp4 -I +site-lib/sexplib pa_sexp_conv.cma" -o sexplib-top

When I run this toplevel, I can open Sexplib just fine, but when I try using the with sexp syntax extension, I get a syntax error.

tshepang
  • 12,111
  • 21
  • 91
  • 136
koschei
  • 819
  • 6
  • 13

1 Answers1

15

It is XXI century already - use ocamlfind :

        Objective Caml version 3.11.2

# #use "topfind";;
- : unit = ()

# #camlp4o;;
/usr/lib/ocaml/dynlink.cma: loaded
/usr/lib/ocaml/camlp4: added to search path
/usr/lib/ocaml/camlp4/camlp4o.cma: loaded
    Camlp4 Parsing version 3.11.2

# #require "sexplib.syntax";;
/usr/lib/ocaml/unix.cma: loaded
/usr/lib/ocaml/bigarray.cma: loaded
/usr/lib/ocaml/nums.cma: loaded
/usr/lib/ocaml/num-top: added to search path
/usr/lib/ocaml/num-top/num_top.cma: loaded
/usr/lib/ocaml/sexplib: added to search path
/usr/lib/ocaml/sexplib/sexplib.cma: loaded
/usr/lib/ocaml/type-conv: added to search path
/usr/lib/ocaml/type-conv/pa_type_conv.cmo: loaded
/usr/lib/ocaml/sexplib/pa_sexp_conv.cmo: loaded

# type t = { x : int; y : float; } with sexp;;
type t = { x : int; y : float; }
val t_of_sexp__ : Sexplib.Sexp.t -> t = <fun>
val t_of_sexp : Sexplib.Sexp.t -> t = <fun>
val sexp_of_t : t -> Sexplib.Sexp.t = <fun>
ygrek
  • 6,656
  • 22
  • 29
  • 4
    Well, paint me orange and call me Susan. Thank you. It'd be really helpful if any learning resource online or in print, anywhere, at all, ever mentioned this, ever. – koschei Sep 16 '11 at 17:08
  • Wow, enjoyed this idiomatic expression :) Here is an article about findlib (in russian) - https://github.com/camlunity/kamlo_wiki/blob/master/Findlib.md - expanded with this example – ygrek Sep 29 '11 at 12:05
  • What does the #camlp4o;; above do? When I enter that part above I don't see any list of modules loaded - but no error either. Doesn't seem to work. – aneccodeal Oct 06 '11 at 06:23
  • Indeed, as of more recent versions, you must `open Sexplib.Std` before defining `type t = ...` in order for the required `{int,float}_of_sexp,sexp_of_{int,float}` standard functions to be in scope. – jrk Oct 11 '12 at 18:16