Skip to content

Replace the Bool commutativity flag on binary operators with a small type #234

Description

@skymanbp

Follow up to #232. Operators built with lift2Decorated or with a positional MkBinaryOp (as the typed API does) set commutativity with a bare Bool, as in lift2Decorated (^) "pow" (Just "^") False 8 (Functions.hs#L463) and MkBinaryOp (==) "eq" (Just "==") True 4 (Typed/Expr.hs#L303). Nothing in the definition says what the Bool means, and #232 fixed two definitions where it was wrong.

Something like this would make each definition readable on its own:

data Commutativity = Commutative | NonCommutative

pow expr i = lift2Decorated (^) "pow" (Just "^") NonCommutative 8 expr (Lit i)

A wrong value is easy to miss because normalize (Expression.hs#L305-L313) swaps the operands of anything marked commutative before derive and filter evaluate it, so the result changes without any error. The aggregation planner (Plan.hs#L201) and the pretty printer (Expression.hs#L472) read the flag too.

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions