Core with 4.04.1

I am currently using ocaml-4.04.1. It seems the only version of Core and sexplib supporting it is v0.9.1.
However, it does not seems to have sexplib.sytax package. Without it I am unsure how to define something as simple as a Set for my own type. All examples recommend with sexp, compare syntax.

By the way, there is no compatible version of ‘comparelib’:

$ opam install comparelib
The following dependencies couldn't be met:
  - comparelib -> type_conv < 112.02.00
Your request can't be satisfied:
  - type_conv.108.00.02 is not available because your system doesn't comply with ocaml-version >= "3.12.1" & ocaml-version < "4.03.0".
  - type_conv.108.07.00 is not available because your system doesn't comply with ocaml-version < "4.03.0".
  - type_conv.108.07.01 is not available because your system doesn't comply with ocaml-version >= "3.12.1" & ocaml-version < "4.03.0".
  - type_conv.108.08.00 is not available because your system doesn't comply with ocaml-version >= "3.12.1" & ocaml-version < "4.03.0".
  - type_conv.109.07.00 is not available because your system doesn't comply with ocaml-version >= "4.00.0" & ocaml-version < "4.03.0".
  - type_conv.109.08.00 is not available because your system doesn't comply with ocaml-version >= "4.00.0" & ocaml-version < "4.03.0".
  - type_conv.109.09.00 is not available because your system doesn't comply with ocaml-version >= "4.00.0" & ocaml-version < "4.03.0".
  - type_conv.109.10.00 is not available because your system doesn't comply with ocaml-version >= "4.00.0" & ocaml-version < "4.03.0".
  - type_conv.109.11.00 is not available because your system doesn't comply with ocaml-version >= "4.00.0" & ocaml-version < "4.03.0".
  - type_conv.109.12.00 is not available because your system doesn't comply with ocaml-version >= "4.00.0" & ocaml-version < "4.03.0".
  - type_conv.109.13.00 is not available because your system doesn't comply with ocaml-version >= "4.00.0" & ocaml-version < "4.03.0".
  - type_conv.109.14.00 is not available because your system doesn't comply with ocaml-version >= "4.00.0" & ocaml-version < "4.03.0".
  - type_conv<112.02.00 is not available because your system doesn't comply with ocaml-version >= "4.02.0" & ocaml-version < "4.03".
  - type_conv<=109.20.00 is not available because your system doesn't comply with ocaml-version >= "4.00.1" & ocaml-version < "4.03.0".
  - type_conv<=109.53.00 is not available because your system doesn't comply with ocaml-version >= "4.00.0" & ocaml-version < "4.03".
  - type_conv<=109.53.02 is not available because your system doesn't comply with ocaml-version >= "4.00.0" & ocaml-version < "4.03".

No solution found, exiting

Please advise, what can I do short of stopping using Core.

The main problem here is that the original Real World OCaml uses syntax extensions based on camlp4, which is now pretty much deprecated in favor of PPX. So now, instead of installing comparelib, you should install ppx_compare.

We’re in the process of refreshing RWO. It’s not complete, but here’s a snapshot of the refresh-in-progress. This shows the new syntax, e.g., [@@deriving compare, bin_io], instead of the old with syntax.

y

Thanks! I have figured out “deriving” syntax and it works for me for sexplib.

However I am still unable to install “comparelib” with my version of OCaml.

Does ppx_compare work for you?

Yes! Thanks!

Last, quick newbie question. Assuming I have type:

  | A
  | B
 ... [@@deriving compare, sexp]

What is the easiest way to make a Set type for it? I am currently using:

  type t = itype
  let compare = compare_itype
  let sexp_of_t = sexp_of_itype
  let t_of_sexp = itype_of_sexp
end

module ITypeSet = Set.Make(IType)

Maybe there is a better way? Thanks!

I’m not sure I’ve spelled this exactly right, but:

module M = struct type t = itype [@@deriving sexp, compare] end
module M_set = Set.Make(M)
```

FWIW, the usual Core-like idiom would be to not use the separate itype type, and instead do something like:

``` ocaml
module Itype = 
  module T = struct
      type t = | A | B [@@deriving sexp, compare]
  end
  include T
  include Set.Make(T)
end
```

You could also do  `include Comparable.Make(T)`, which gives you sets and maps and other useful comparison-based operations.

y
1 Like

Tanks again. Although idiomatic approach will require me to use IType.t instead of itype. I personally prefer the later, as less cluttered notation.