~icefox/garnet#64: 
Pattern matching

Time to actually design it.

https://gleam.run/news/v0.33-exhaustive-gleam/ has some good resources.

Status
REPORTED
Submitter
~icefox
Assigned to
No-one
Submitted
6 months ago
Updated
2 months ago
Labels
T-DESIGN

~icefox 5 months ago

https://compiler.club/compiling-pattern-matching/ has decent implementation stuff.

In terms of actual design, so far I'm fine basically co-opting Rust's semantics without any major innovations or design changes. Captures and conditions are important but not particularly common, at least in Rust code, so I kinda dislike its Foo(x, y) @ x style but don't have a pressing need to even implement it, let alone try to improve it.

match foo with
  | Thing { a, b, _ } -> thing1
  | Other { .x = x, .y = y } -> thing2
  // syntactic sugar for the above?
  | Other2 { x, y } -> thing3
  | _ -> default
end

The .x =... syntax instead of x: ... might make distinguishing variable captures vs. matching on variables easier, ponder it more later.

Questions: if let? while let? I'm going to assume that every let is a pattern match 'cause that's nice; are we going to bother with pattern matching in function args? Eh, probably but it's not critical so far, we'll see how hard it is.

~icefox 2 months ago

https://perso.ens-lyon.fr/thais.baudon/icfp2023.pdf has some good references on compiling pattern matching. https://dl.acm.org/doi/10.1145/1411304.1411311 seems to be the most recent. PDF of it available here: https://www.cs.tufts.edu/~nr/cs257/archive/luc-maranget/jun08.pdf

Register here or Log in to comment, or comment via email.