Sitelet https://github.com/hyperpolymath/affinescript/issues/49
Skip to content

[AI.a2ml] Add validation-chain-over-tuple-match idiomatic pattern #49

Description

@hyperpolymath

Proposal

Add an (idiomatic-pattern) for Validation chain over tuple match. case (a, b, c, d, e, f, g) of (Ok, Ok, Ok, ...) => ... blows ambiguity-resolution budgets at N≥5. The Validation applicative chain is the right shape.

Source observation

ProvenBridge's extractLevelData had a 7-tuple case match ((devicesR, zonesR, guardsR, ztR, hasPbxR, pbxIpR, pbxWxR)). Idris2's default %ambiguity_depth of 3 couldn't resolve it; even at 12 the cascade into surrounding code was fragile. Splitting into 4-tuple + 3-tuple matches fixed it. The Validation applicative gives this as one-liner MkRecord <$> a <*> b <*> c <*> ... <*> g.

Suggested patch (LESSONS.md L5)

(pattern
  (name "validation-chain-over-tuple-match")
  (composition "Validation applicative + <*>")
  (purpose "Accumulate errors across N independent extractions without N-tuple matches.")
  (anti-pattern "case (a, b, c, d, e, f, g) of (Ok, Ok, Ok, ...) — N>=5 tuple matches blow type inference.")
  (sketch "MkRecord <$> a <*> b <*> c <*> d <*> e <*> f <*> g"))

Filed from idaptik Wave 3 pilot. See LESSONS.md and PILOT.md. Idaptik commit hyperpolymath/idaptik@aef38db.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions