Zulip Chat Archive
Stream: lean4
Topic: Parsing inductive data structures via FFI
Leni Aniva (Mar 07 2024 at 00:09):
Is there a way to parse inductive data structures (e.g. Expr
objects) via the FFI?
For example if lean_object *obj
is an Expr
, how can I read which constructor produced it and read the arguments to that constructor?
Abdalrhman M Mohamed (Mar 07 2024 at 02:41):
lean_is_ctor
and lean_ptr_tag
are probably the functions you're looking for. I would recommend you follow the kernel's approach of defining an enum class for the datatype (e.g., expr_kind
) and a function (e.g., expr::kind
) that returns the enum directly.
James Gallicchio (Mar 07 2024 at 08:22):
honestly https://docs.rs/lean-sys/latest/lean_sys/ might be helpful if only for having generated docs :P
Leni Aniva (Mar 07 2024 at 08:23):
James Gallicchio said:
honestly https://docs.rs/lean-sys/latest/lean_sys/ might be helpful if only for having generated docs :P
I'm kind of skeptical about this project since it doesn't pin down the Lean version and also it doesn't really encapsulate the interface in lean.h
. I find that bindgen is good enough for my purposes
Mario Carneiro (Mar 07 2024 at 17:23):
I have a project which does a higher level interface but it's a lot more work to design that
Mario Carneiro (Mar 07 2024 at 17:24):
it doesn't pin the lean version because this would cause rust versioning issues, but lean.h doesn't change much
Mario Carneiro (Mar 07 2024 at 17:29):
I'm not really sure how best to do versioning in lean-sys. The lean version pin should happen in the project using lean-sys
Mario Carneiro (Mar 07 2024 at 17:51):
updated to lean 4.6.0
Last updated: May 02 2025 at 03:31 UTC