realworldocaml/book

Query handler example - incomplete information

robertblackwell opened this issue · 1 comments

This is by way of a bit of a whinge, though by publishing this info it might help some other poor newbie like me.

Its also a more general comment about what I have found to be an impediment and discouragement to learning Ocaml. Namely a lot of simple things are left un-said and they accumulate to be a real impediment.

I am working on the query handler given as an example in "Real World Ocaml" and got to the point of

#require ppx_jane";;
type u = {a:int; b: float} [@@deriving sexp];;

to which I got the error message "Error: Unbound value int_of_sexp"

well a few hours, and much hair tearing, latter I had the following series of utop commands

#require "base";;
open Base;;
#require ppx_jane";;
type u = {a:int; b: float} [@@deriving sexp];;
sexp_of_u {a=3; b=7.}

which gave :

- : Sexp.t =
Sexplib0.Sexp.List
 [Sexplib0.Sexp.List [Sexplib0.Sexp.Atom "a"; Sexplib0.Sexp.Atom "3"];
  Sexplib0.Sexp.List [Sexplib0.Sexp.Atom "b"; Sexplib0.Sexp.Atom "6"]]

Not at all what I expected nor what the book predicted. So more searching and eventually the additional command

#install_printer Sexplib.Sexp.pp_hum

gave the expected output.

Yeah, this is a general problem in the book. There are installation instructions that tell you what you need to do (linked to from the guided tour and from the prologue:

http://dev.realworldocaml.org/install.html

but the document is a little long, and it's easy to miss the right invocation:

#use "topfind";;
#thread;;
#require "core.top";;

And the "open Core" is at the top of the chapter, as it is at the top of nearly every chapter. ("open Base" works too for what you did.)

I'm honestly not sure how to make this better. Open to suggestions.