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

Nested patterns in array patterns #354

Open
LightAndLight opened this issue Feb 12, 2023 · 1 comment
Open

Nested patterns in array patterns #354

LightAndLight opened this issue Feb 12, 2023 · 1 comment
Labels

Comments

@LightAndLight
Copy link
Owner

When I implemented #81 I only implemented a single level of pattern matching:

case x of
  [a, b, c] -> ...
  ...

Supporting nested patterns seems pretty complicated:

case x of
  [1, 2, 3] -> ...
  [2, 2, 4] -> ...
  [] -> ...
  [_, _] -> ...
  _ -> ...

A single level of array patterns has a pretty good cost:benefit ratio right now. I'm noting that I might want nested pattern support in the future. The Implementation of Functional Programming Languages1 Chapter 5 has a good general algorithm for un-nesting pattern matches.

Footnotes

  1. Peyton Jones, S. L. (1987). The implementation of functional programming languages (prentice-hall international series in computer science). Prentice-Hall, Inc..

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

@LightAndLight
Copy link
Owner Author

Bump, I expected this today.

    bind args <- case args of
      [arg1, arg2] ->
        ...
      ["-h"] ->
        exitWithHelp (None ())
      ["--help"] ->
        exitWithHelp (None ())
      _ ->
        exitWithHelp (Some "expected 2 arguments, got ${int.toString (array.length args)}")

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

No branches or pull requests

1 participant