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

Improve the left-hand side flattener #54

Closed
steinerkelvin opened this issue Feb 2, 2022 · 3 comments
Closed

Improve the left-hand side flattener #54

steinerkelvin opened this issue Feb 2, 2022 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@steinerkelvin
Copy link

steinerkelvin commented Feb 2, 2022

HVM's runtime only handles direct, non nested matches. So, for example, this is a valid rule:

(Foo (Bar xs)) = (A xs)

But this is not:

(Foo (Bar (Cons x xs))) = (A (Cons x xs))

Because there is a nested match. In order for these cases to work, we must split the left-hand of nested patterns, into many non nested equations. Currently, the language has a flattener that is limited, and will fail in some cases. For example, the function below:

Fn (Bar (Cons ...)) = A
Fn (Bar Nil)        = B
Fn x                = C

Should be compiled to:

Fn (Bar _0)         = (Fn.0 _0)
  (Fn.0 (Cons x y)) = A
  (Fn.0 Nil)        = B
  (Fn.0 x)          = C
Fn x                = C

But the current flattener can't deal with that.

@rigille
Copy link

rigille commented Feb 2, 2022

i need this so much. i'm trying to implement it right now

@bredelings
Copy link

The method for doing this is described in chapter five "Efficient compilation of Pattern-Matching" by Wadler in "The Implementation of Functional Programming Languages" (1987) by Simon L Peyton-Jones

https://www.microsoft.com/en-us/research/wp-content/uploads/1987/01/slpj-book-1987-small.pdf

@VictorTaelin
Copy link
Member

Closing this issue since the flattener on master now covers all cases.

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

No branches or pull requests

4 participants