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

match-of with ADT (together with defunion). #146

Open
jsulmont opened this issue Mar 8, 2023 · 1 comment
Open

match-of with ADT (together with defunion). #146

jsulmont opened this issue Mar 8, 2023 · 1 comment

Comments

@jsulmont
Copy link

jsulmont commented Mar 8, 2023

Hi
Assuming the following following

(defunion ski
  S
  K
  I
  (E (lhs ski) (rhs ski)))

, the following code

(defun blah (expr)
(match-of ski expr
  (K K)
  (I I)
  (S S)
  ((E I x) (interpret x))))

interprets I in the (E I x) clause as a variable rather than the I unit type.
Or have I missed something (probably)?

Thank you!

@jsulmont
Copy link
Author

jsulmont commented Mar 8, 2023

Answering my own question (after reading pattern-type) ... the correct way of doing this is:

(defun interpret (expr)
  (match-of ski expr
    ((or S K I)  expr)
    ((E (eql I) x) (interpret x))))

(also helpful to read about trivia...)

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