
Sometimes I have a type like: data A = A1 Int | A2 Int Int Then if I want to do pattern matching and ignore the parameters I do: f (A1 _) = .. f (A2 _ _) = ... But that's annoying; I need to remember how many parameters each one has! Yesterday I learned I can just do this: f A1 {} = ... f A2 {} = ... And GHC is happy. Is this expected? Am I the last to learn about this trick? -- Noon van der Silk, ن http://silky.github.io/ "My programming language is kindness."

I’ve known it for a while and use it now and then. There are quite a few packages on Hackage that use it: https://hackage-search.serokell.io/?q=%5BA-Z%5D%5Ba-zA-Z0-9%27_%5D*%5Cs%2B%5...
On 30 Nov 2023, at 14:46, Noon van der Silk
wrote: Sometimes I have a type like:
data A = A1 Int | A2 Int Int
Then if I want to do pattern matching and ignore the parameters I do:
f (A1 _) = .. f (A2 _ _) = ...
But that's annoying; I need to remember how many parameters each one has!
Yesterday I learned I can just do this:
f A1 {} = ... f A2 {} = ...
And GHC is happy.
Is this expected? Am I the last to learn about this trick?
-- Noon van der Silk, ن
"My programming language is kindness." _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

Yes. You're just using record pattern match with no records. Why would it be unexpected? On 30.11.2023 14:46, Noon van der Silk wrote:
Sometimes I have a type like:
data A = A1 Int | A2 Int Int
Then if I want to do pattern matching and ignore the parameters I do:
f (A1 _) = .. f (A2 _ _) = ...
But that's annoying; I need to remember how many parameters each one has!
Yesterday I learned I can just do this:
f A1 {} = ... f A2 {} = ...
And GHC is happy.
Is this expected? Am I the last to learn about this trick?
-- Noon van der Silk, ن
"My programming language is kindness."
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

It was unexpected to me because A1 and A2 were not defined as record constructors. (Since I discovered it I now use it regularly; it's very nice.) On Thu, Nov 30, 2023 at 02:58:43PM +0100, David Kraeutmann wrote:
Yes. You're just using record pattern match with no records. Why would it be unexpected?
On 30.11.2023 14:46, Noon van der Silk wrote:
Sometimes I have a type like:
data A = A1 Int | A2 Int Int
Then if I want to do pattern matching and ignore the parameters I do:
f (A1 _) = .. f (A2 _ _) = ...
But that's annoying; I need to remember how many parameters each one has!
Yesterday I learned I can just do this:
f A1 {} = ... f A2 {} = ...
And GHC is happy.
Is this expected? Am I the last to learn about this trick?

Yes I agree with Tom; it's at least a bit unexpected because unlike with records, there is (if I understand well) nothing I can write inside the {} that would actually be valid for that type. On Thu, 30 Nov 2023 at 14:06, Tom Ellis < tom-lists-haskell-cafe-2023@jaguarpaw.co.uk> wrote:
It was unexpected to me because A1 and A2 were not defined as record constructors. (Since I discovered it I now use it regularly; it's very nice.)
On Thu, Nov 30, 2023 at 02:58:43PM +0100, David Kraeutmann wrote:
Yes. You're just using record pattern match with no records. Why would it be unexpected?
On 30.11.2023 14:46, Noon van der Silk wrote:
Sometimes I have a type like:
data A = A1 Int | A2 Int Int
Then if I want to do pattern matching and ignore the parameters I do:
f (A1 _) = .. f (A2 _ _) = ...
But that's annoying; I need to remember how many parameters each one has!
Yesterday I learned I can just do this:
f A1 {} = ... f A2 {} = ...
And GHC is happy.
Is this expected? Am I the last to learn about this trick?
Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- Noon van der Silk, ن http://silky.github.io/ "My programming language is kindness."

Yes, you're the last to learn about it; we were all wondering when you
would figure it out. ;-)
It's definitely "folklore", I can't remember where I first learned about
it. I agree with Tom that it's surprising (but nice) that it works even
with data types that were not declared using record syntax. I also always
find it surprising that record update or matching binds more tightly than
function application, so that no parentheses are needed. Sometimes I feel
like it would actually look nicer to write
f (A1 {}) = ...
but then hlint yells at me. (Yes, I'm aware I can turn off individual
hlint warnings. =)
-Brent
On Thu, Nov 30, 2023 at 7:47 AM Noon van der Silk
Sometimes I have a type like:
data A = A1 Int | A2 Int Int
Then if I want to do pattern matching and ignore the parameters I do:
f (A1 _) = .. f (A2 _ _) = ...
But that's annoying; I need to remember how many parameters each one has!
Yesterday I learned I can just do this:
f A1 {} = ... f A2 {} = ...
And GHC is happy.
Is this expected? Am I the last to learn about this trick?
-- Noon van der Silk, ن
"My programming language is kindness." _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

Like others, this caught me by surprise, but now I use it regularly.
I use hlint to advise me on the quality of my Haskell code. I have learned many, many good ideas from hlint.
As of a few years ago, hlint begins to recommend changing f (A3 _ _ _) = ... to f A3 {} = ... as soon as there are three or more components.
On Thursday, November 30, 2023 at 09:12:09 AM EST, Brent Yorgey
participants (6)
-
Brent Yorgey
-
David Kraeutmann
-
J. Reinders
-
Mark McConnell
-
Noon van der Silk
-
Tom Ellis