Core-compatible graph library

44 views
Skip to first unread message

s...@basus.me

unread,
Jan 27, 2017, 2:59:46 PM1/27/17
to ocaml-core
Hi,
It seems like there isn't a graph module as part of Core. I'm looking for something like OCamlgraph ( http://ocamlgraph.lri.fr/index.en.html ), but that works with Core's idioms, and hopefully supports ppx extensions like show and Sexp. Any suggestions?

Thanks,
Basu

Yaron Minsky

unread,
Jan 27, 2017, 3:08:42 PM1/27/17
to ocaml...@googlegroups.com
Sadly, I know of no such library.

y
> --
> You received this message because you are subscribed to the Google Groups
> "ocaml-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ocaml-core+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

s...@basus.me

unread,
Jan 28, 2017, 7:00:12 AM1/28/17
to ocaml-core
Hi,
It looks like Core doesn't come with a graph library, and I'm looking for a compatible one. I've been using Ocamlgraph (http://ocamlgraph.lri.fr/index.en.html), but it doesn't work quite right with Core, especially in terms of naming conventions and using PPX derivers like show and sexp. Is there a similar library I can use instead?
Thanks,
Basu

Ashish Agarwal

unread,
Feb 1, 2017, 9:37:46 AM2/1/17
to ocaml...@googlegroups.com
Ocamlgraph's types are abstract, so you can't automatically apply derivers on them. You have to define your own, but that can be pretty easy. One way is to convert the abstract type to some other type, and derive the serializer on that type. Something like this:

module G : sig
  include module type of Graph.Persistent.Digraph.Concrete(Int)
  val of_list : int list -> t
  val to_list : t -> int list
  val sexp_of_t : t -> Sexp.t
  val t_of_sexp : Sexp.t -> t
end = struct
  include Graph.Persistent.Digraph.Concrete(Int)
  let of_list (l : int list) : t = (* implement this *)
  let to_list (t : t) : int list = (* implement this *)
  let sexp_of_t t = [%sexp_of: int list] (to_list t)
  let t_of_sexp sexp = [%of_sexp: int list] sexp |> of_list
end


--
You received this message because you are subscribed to the Google Groups "ocaml-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ocaml-core+unsubscribe@googlegroups.com.

Jeremie Dimino

unread,
Feb 1, 2017, 10:01:16 AM2/1/17
to ocaml...@googlegroups.com
There is also a Sexpable.Of_sexpable functor that should help here.
>> email to ocaml-core+...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "ocaml-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ocaml-core+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Jeremie
Reply all
Reply to author
Forward
0 new messages