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

How should we render patterns/bindings? #54

Open
hmac opened this issue Feb 11, 2021 · 4 comments
Open

How should we render patterns/bindings? #54

hmac opened this issue Feb 11, 2021 · 4 comments

Comments

@hmac
Copy link

hmac commented Feb 11, 2021

We realised in https://github.com/hackworthltd/vonnegut/pull/285 that we should distinguish between (for want of better terms) patterns and expressions, where patterns define and bind new variables and expressions reference existing variables. In text view, patterns tend to appear on the left hand side of arrows. For example, x is a pattern in each of these:

λ x → ...

case e of
  Just x → ...

let x = e
 in ...

Whereas x is an expression (specifically, a variable) in each of these:

λ y → x

case x of
  ...

let y = x
 in ...

Patterns in Vonnegut have two forms:

  • variable patterns, e.g. x
  • constructor patterns, e.g. Just x

We currently only allow constructor patterns in case branches and only at the top level, so e.g. Cons (Just x) xs is not a valid pattern.

Patterns have a different a smaller set of rules governing their behaviour compared to expressions. As a user editing a program, the only things you can do to a pattern are:

  • rename it
  • replace it with another pattern
  • (possibly) delete it?

Patterns also don't really "have types" in the same way as expressions, but we can still associate them with the type of expression they match.

(There's probably more info I can add here - I'll do that shortly)

@dhess
Copy link
Member

dhess commented Mar 10, 2021

I'm marking this as medium priority, as it's bundled in with all of the other various parameter-ish issues that are already medium priority.

@hmac hmac assigned hmac and unassigned hmac Apr 7, 2021
@dhess
Copy link
Member

dhess commented Jun 14, 2021

Here's another way in which we should do a better job rendering patterns. Consider the following definition of map :: ∀α . ∀β . (α → β) → List α → List β:

Screen Shot 2021-06-14 at 5 02 07 PM

We render the Nil and Cons x xs1 patterns in the case branches without their type applications. For consistency (and I think this will be especially important in eval mode, when the student is visually trying to match patterns in the scrutinee to the corresponding branch pattern), we should render them as Nil @ α and Cons @ α x xs1.

@dhess
Copy link
Member

dhess commented Jun 27, 2021

I would like to try rendering constructors in case branches with their Apps in time for user testing. Therefore, I'm going to move this back to "todo" for the Demo project and mark it medium priority.

@dhess
Copy link
Member

dhess commented Sep 5, 2021

Nope, not gonna happen in our current frontend.

@dhess dhess transferred this issue from another repository Sep 18, 2021
@dhess dhess transferred this issue from another repository Sep 23, 2021
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

2 participants