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

Pattern matching: What, where, how #13

Open
Kleidukos opened this issue Jun 3, 2021 · 2 comments
Open

Pattern matching: What, where, how #13

Kleidukos opened this issue Jun 3, 2021 · 2 comments

Comments

@Kleidukos
Copy link
Contributor

Basically, there are two types of pattern matching techniques that we want to cover:

  1. Destructuring ADTs and lists (and especially user-defined datatypes
  2. Other techniques for pattern matching, such as:
    • Functions Guards
    • Pattern Guards
    • As-patterns
    • View Patterns

The first type should be mentioned in the lesson about user-defined ADTs.
The second type will need its own lesson.


cc @DrewFenwick

@DrewFenwick
Copy link
Contributor

Good learning materials on all the forms of pattern matching are spread out all over the place
and somewhat hard to discover if you aren't specifically looking for them:
Currently view patterns are best documented by the GHC user's guide,
as-patterns are coverd by A Gentle Introduction to Pattern Matching and the Haskell Wikibook
while Pattern Guards are mentioned a little hither and thither but generally hard to find or even hear of at all unless you're specifically looking for them (which is surprising for an unextended Report Haskell feature!)

Having all forms of pattern matching covered by Haskell School would fill a role that isn't currently filled very well in my opinion.
If lesson headings were such that someone searching specifically for "patterns" could find all our coverage of them too, that would be even better.

Lesson Order

In tutorials, list matching patterns generally get introduced fairly early; often earlier than ADTs.
Covering how to pattern match on all forms of ADT and explaining that patterns can only take apart what constructors put together requires an understanding of constructors that is probably best gained from learning how to make ADTs.

We'd be tying our hands too much to only show pattern matching until after ADTs,
but violating the pedagogic order to introduce pattern matching on ADTs before introducing ADTs, so things need to be split.

On talking with @Kleidukos, IIRC we felt that the appropriate order was to introduce pattern matching on lists early as nessecary,
cover pattern matching on ADTs in the same section that introduces ADTs,
and have an "advanced pattern matching" section that covered all the myriad special pattern matching syntaxes.

Maybe we ought to have a styled "interesting note" box in the ADT section that points out that the : operator and [] value are just constructors of the list type, which is a built in sum type, and that's why pattern matching on (x:xs) works, while xs ++ ys cannot?

More topics

Here are some more pattern matching topics we might want to cover:

  • Exhaustive and inexhaustive patterns.
  • How patterns nest.
  • Why patterns sometimes have brackets around them and sometimes don't.
  • How function pattern matches are case expressions under the hood.
  • Irrefutable vs Refutable patterns.
  • Strictness semantics of let vs case/function patterns
  • BangPatterns
  • How lazy case patterns and strict let patterns desugar
  • Pattern synonyms?

All of the topics we cover will need an appropriate home in the lesson order, and any topics covering language extension features need to appropriately inform the user.

@Kleidukos
Copy link
Contributor Author

Fixed by #32

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