Pattern synonym in record update throws syntax error
Summary
Using a pattern synonym in a record update results in a syntax error. However, wrapping the pattern synonym in parentheses works. This is surely unintended behavior.
Steps to reproduce
{-# LANGUAGE PatternSynonyms #-}
data R = R { x :: () }
pattern P :: R
pattern P = R { x = () }
error = P { x = () } -- error: Constructor ‘P’ does not have field ‘x’
works = (P) { x = () } -- workaround
Expected behavior
Being able to use pattern synonyms directly in record updates without needing parentheses.
Environment
- GHC version used: any
Discussion on libera.chat:#haskell
23:02:06 Irssi: Join to #haskell was synced in 69 secs
23:06:47 <yin> this is fun!: i have a bidirectional pattern synonym and try to use record update syntax like `MyPattern { x = ... }` i can get the error `constructor MyPattern does not have field 'x'`
23:07:10 <yin> the solution: `(MyPattern) { x = ... }`
23:08:24 <yin> this feels kind of lispy
23:10:51 <yin> also feels like PatternSynonyms could be patched to allow the former
23:32:35 <c_wraith> that definitely sounds like a feature it should have.
23:32:54 <c_wraith> If it allows you to create a record pattern, it should use the same syntax as a record pattern...
23:33:05 <monochrom> To me it feels like kind of CPP. "#define add(x,y) ((x)+(y))" :)
23:33:49 <monochrom> PPP = pattern pre-processor >:)
23:36:51 <geekosaur> record update syntax is a bit weird
23:37:38 <c_wraith> like at the parser level?
23:37:41 <monochrom> It's probably a simple oversight in the parser.
23:39:37 <geekosaur> yeh, it's probably missing a case for patsyns so it makes you fall into the parenthesized expression case
...
23:47:13 <geekosaur> anyway it sounds like someone should file a bug on gitlab
Edited by sheaf