[Agda] A feature request: typed pattern synonyms.

Roman effectfully at gmail.com
Sat Jun 18 12:18:51 CEST 2016


Hi, I'm doing some generic programming and defining lots of pattern
synonyms, but they are not equivalent to constructors due to their
untyped nature. E.g. I have

    pattern _∷_ x xs = cons₁ (x , xs , lrefl)

Clearly, Agda can't infer that `_∷_` has type `∀ {α} {A : Set α} -> A
-> List A -> List A`, so the inferred type of `2 ∷ []` is `μ (_Ds_57 x
xs) (_j_58 x xs)` instead of `List ℕ`, i.e. completely unspecified. It
means that I need both a pattern `_∷_` and an operator

    _∷′_ : ∀ {α} {A : Set α} -> A -> List A -> List A
    _∷′_ = _∷_

to use on the RHS. It's rather inconvenient to have a pattern and a
function instead of just one constructor, especially in my case as I
want to figure out whether it's possible to type check existing code
after changing data definitions to their generic counterparts.

Ideally, I would like to write

    pattern
      _∷_ : ∀ {α} {A : Set α} -> A -> List A -> List A
      x ∷ xs = cons₁ (x , xs , lrefl)

Is it possible to implement such a feature? Or maybe something else
that would allow to use pattern synonyms as genuine constructors?


More information about the Agda mailing list