Skip to content

Direct rewrite rules #29

@jameshaydon

Description

@jameshaydon

At the moment rewrite rules have to specified using a pattern language. For example:

addCommutes = pat (BinOp Add "a" "b") := pat (BinOp Add "b" "a")

This rewrite rule could also be specified with a function:

addCommutes = \case
  Fix (BinOp Add a b) -> Just (Fix (BinOp Add b a))
  _                   -> Nothing

I'll refer to this as a "direct" rewrite rule.

I imagine there are advantages to the pattern matching approach, but I was wondering if it would also be possible to specify rewrite rules using the "direct" approach too? The sort of situation I would like to handle is for example when your language functor has a case like:

data F a = Foo Int a | ...

and you want to match Foo n x only when n satisfies some property, and use n to rewrite the term in some non-trivial way.

And thanks for the great package!

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