catala icon indicating copy to clipboard operation
catala copied to clipboard

Feature debate: range patterns

Open protz opened this issue 4 years ago • 1 comments

It would be convenient to do:

match e₁ with pattern
-- Cons1 .. Cons2: eā‚‚

where the pattern matches any constructors present in the enumeration declaration between Cons1 and Cons2.

This, of course, poses problems, such as semantics changing when constructors are re-ordered. But, in my use-case, I have something like:

declaration enumeration Violation:
  -- Section286_102   # Licensing
  -- Section291_2     # Reckless driving of vehicle or riding of animals; penalty
  -- Section291_3_1   # Consuming or possessing intoxicating liquor while operating motor vehicle or moped
  -- Section291_3_2   # Consuming or possessing intoxicating liquor while a passenger in a motor vehicle
  -- Section291_3_3   # Storage of opened container containing intoxicating liquor or consumption at scenic lookout
  -- Section291_4_6   # Driving after license suspended or denied for noncompliance with an order of support
  -- Section291_8     # Freight on motor cars; projection of, prohibited
  -- Section291_9     # Freight; on running board
  -- Section291_11_5  # Child passenger restraints
  -- Section291_11_6  # Mandatory use of seat belts, when, penalty
  -- Section291_11    # Riders and passengers under seven years of age on motorcycles and motor scooters prohibited
  -- Section291_12    # Inattention to driving
  -- Section291_13    # Traffic laws apply to persons driving mopeds
  -- Section291_14    # Pickup trucks; passenger restrictions

and oftentimes, say in a followup statute, there will be something like "for infractions between 291-X and 291-Y"... I don't want to switch to pairs of integers (because I would lose the benefits of exhaustiveness checking), so an alternative might be to enforce that such patterns impose that the type declaration constructors be sorted by lexicographic order

protz avatar Apr 28 '21 21:04 protz

Thanks Jonathan! I guess in the meantime you can hide that verbose matching in a helper variable, so that lawyers don't have to review this big pattern match. I'm not a fan of this lexicographic ordering enforcement, since in other situations you may want to group cases together in the type declaration in a way that is more semantic than lexicographic.

denismerigoux avatar Apr 29 '21 08:04 denismerigoux