Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

number of occurences of free variable & access to free variable list #29

Open
adelaett opened this issue Apr 4, 2023 · 2 comments
Open

Comments

@adelaett
Copy link
Contributor

adelaett commented Apr 4, 2023

Dear Bindlib maintainers,

We are using your library in Catala and we are very happy about it. However, while trying to implement heuristics for some optimization scheme, we find that the API you provide does not give some important information. Namely, the number of occurrences for a specific free variable.

Moreover, while you provide a way to get all the free variable in the form of a context, you do not provide a way to get the uid of the variables, that are sometime pretty important for debugging purpose. It is also possible that we are wrongly using your library. Is is possible to provide a function to get access to the free variables ?

val number_occurences: 'a box -> 'b var -> int
val free_variables: 'a box -> 'a var list 

Best,

Alain

@rlepigre
Copy link
Owner

rlepigre commented Apr 4, 2023

Thanks for using Bindlib!

For number_occurrences, we currently do not compute the occurrence count for variables, but I think adding this could be achieved with a straight-forward extension of the 'a box type.

For free_variables, we used to have a function with exactly the signature you give in previous versions, and we overlooked the fact that we were losing access to the unique identifier by doing so. We could re-instate such a function easily.

I'll see what I can do to add these two features when I have a minute, hopefully soon.

@craff
Copy link
Collaborator

craff commented Apr 4, 2023

Hello and thanks for the nice compliment about our word, it is always nice to hear.

For number_occurences, it would be relatively easy to keep, but means some extra work that most usage won't need. You can have your own box type build above bindlib's to do that, keeping the same interface.

For free_variables, it is not provided because currently we still use Obj.t to handle variables of different type and returning our internal type any_var would be of no use. Moving to existential type and removing Obj would be nice,
but it would require to carry a representation of the types used by variables and check that representation at runtime even when substituting a variable. This will make the library much harder to use while most use case only have one type of variables. Another solution would be to turn bindlib into a functor...

Again having you own box type above bindlib should solve the problem, as you know how many type of variables you use.

I just made a pull request with an example doing this.

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants