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

Code duplication in mutually recursive functions #162

Open
lastland opened this issue Nov 3, 2020 · 0 comments
Open

Code duplication in mutually recursive functions #162

lastland opened this issue Nov 3, 2020 · 0 comments

Comments

@lastland
Copy link
Collaborator

lastland commented Nov 3, 2020

Issue by trommler
Thursday Aug 13, 2020 at 14:13 GMT
Originally opened as antalsz/hs-to-coq#162


When translating mutually recursive functions hs-to-coq generates one Definition, which contains a fix, for each of the mutually recursive functions. Each of those definitions must contain code for all functions in the mutual fixed point leading to code duplication linear in the number of mutually recursive functions in the mutual fixed point.

A small reproducer for this issue is the testcase for mutual recursion. In the generated file Mutrec.v note the two definitions that differ only in the for clause at the end.

Code duplication can be avoided by translating to a Fixpoint as follows:

Fixpoint f1 (arg_0__: list T) : list T
        := match arg_0__ with
           | nil => nil
           | cons x xs => (cons x (f2 xs))
           end with f2 (arg_0__ : list T) : list T
                      := match arg_0__ with
                         | nil => nil
                         | cons y ys => (cons y (f1 ys))
                         end.
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

1 participant