Skip to content
This repository was archived by the owner on Nov 18, 2023. It is now read-only.
This repository was archived by the owner on Nov 18, 2023. It is now read-only.

Parametric (rather than overloaded) matrix multiplication? #62

@kindaro

Description

@kindaro

Sometimes one may wish to use different operations for matrix multiplication than the usual ring operations of the Num instance. For instance, one may find the transitive closure of a relation (represented by a boolean matrix) by iterating matrix multiplication with ^ (Haskell &&) instead of the algebraic boolean addition. Were a Num instance to be defined with the ^ operation, it would not have a well-behaving negate, so defining such an instance is a poor and dangerous solution. But, due to the absence of parametric matrix multiplication, defining such a broken instance is the only way to obtain the transitive closure using matrix multiplication on Bool.

I propose that we add operations multStdBy and so on, that accept two functions as arguments — one to use as addition, another as multiplication. Note that the ^ operation can be defined in terms of the algebraic operations (as x ^ y = x + y + xy) which can be safely represented by a Num instance for a data type with two members, giving a nice and safe solution for my example.

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