Sexp type
(I'm creating an issue for the first part of my Discuss message at https://discuss.ocaml.org/t/combinator-library-for-extracting-data-for-s-exps/10153/7 )
I am using the Sexplib
parsers (Sexp.load_sexp), which return a value of type Sexplib.Type.t which is not the same as Csexp.t
-- they are two identical but incompatible type declarations. I tried to find a parsing function in Csexp
, but my understanding is that the library only deal with the binary encoding of s-expressions, not their common textual format, so I ended up writing a conversion function by hand.
let rec port : Sexplib.Sexp.t -> Csexp.t = function
| List items -> List (List.map port items)
| Atom s -> Atom s
in
Sexplib.Sexp.load_sexp tmp
|> port
Note that Csexp
itself does not suffer from this issue as it offers a functor parametrized over the sexplib type, so I could call Csexp.Make(Sexplib.Type)
and get compatible types. Maybe Sexp_decode
could offer a functorized interface in the same way? (Or maybe Csexp
and Sexplib
could agree to share their type definition with a common dependency.)