-
Notifications
You must be signed in to change notification settings - Fork 345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typed pattern synonyms #2069
Comments
Typed pattern synoyms could be overloaded (and overload constructors), this would be handy. However, this would probably then defeat your purpose, Roman, as they will be only checkable, not inferable. Only for non-ambiguous pattern synonyms one could get inference, like for unambiguous constructors now. |
Thanks for considering the request. I don't expect pattern synonyms (or constructors) to be both inferrable and overloaded at the same time (is it even possible without adding something like union types to the language?). For my use case I need pattern synonyms to be equal in power to constructors (because I want to replace constructors in existing code with corresponding pattern synonyms), i.e. either inferrable or overloaded. It seems pattern synonyms are not equivalent to constructors even as checkable terms currently. Here is a file which defines the
|
I haven't run into the need for inferrable pattern synonyms, but I've often wished for overloadable ones. Here's a common design pattern I'm using: data D (i : I) : Set where
c : ∀ {j} → A → i ≡ f j → D i
pattern c! x = c x refl It's really annoying that I can reuse the One might consider deferring name resolution in pattern synonyms to the use site, allowing the single definition of |
@effectfully : What you actually want is functions that you can also use on the left hand side.
Agda could evaluate the second clause to
and then do pattern matching as usual. In general, I think your proposed typed pattern synonyms require an entirely different mechanism than the current pattern synonyms, which are basically macros expanded by the scope checker before we reach the type checker. |
@andreasabel, is it easier to allow functions on lhs than to adjust the meaning of patterns on rhs? Stuff like pattern
suc2 : Nat -> Nat
suc2 x = suc (suc x) can be processed as follows: first, Though, I like the idea of having functions on lhs. I needed this a few times. |
Being able to write module Nary where
open import Agda.Builtin.Nat
N-ary : Nat → Set → Set
N-ary 0 A = A
N-ary (suc n) A = A → N-ary n A
data Nat' : Set where
zero : N-ary 0 Nat'
succ : N-ary 1 Nat' We could imagine these "typed patterns synonyms" to similarly be any well-typed expression as long as it evaluates to something that qualifies as a pattern. |
Should not |
Roman writes:
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
Clearly, Agda can't infer that
_∷_
has type∀ {α} {A : Set α} -> A -> List A -> List A
, so the inferred type of2 ∷ []
isμ (_Ds_57 x xs) (_j_58 x xs)
instead ofList ℕ
, i.e. completely unspecified. It means that I need both a pattern_∷_
and an operatorto 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
Is it possible to implement such a feature? Or maybe something else that would allow to use pattern synonyms as genuine constructors?
The text was updated successfully, but these errors were encountered: