Pattern matching

In pattern matching, we attempt to match values against patterns and, if so desired, bind variables to successful matches.
~ Wikibooks article on Haskell/Pattern matching

This project implements pattern matching in Snap!, using predicates and upvars. Each pattern is implemented as a custom block with upvars, that returns a predicate that takes a value to match against. If the match succeeds, the predicate sets the upvars and reports true. Otherwise, it reports false.

Included patterns are those relating to a type-parameter-less Maybe type (which is used by the pattern matching system to distinguish non-matches from matches with falsy values), lists and list items, along with patterns that allow you to combine other patterns with the equivalent of logical "and".

https://cloud.snap.berkeley.edu/site/project?user=rdococ&project=Pattern%20matching

Nice. And I learned that "Just" means "singleton?". :slight_smile:

Fwiw, here's my pattern matcher:

1 Like