[Haskell-cafe] Strange quirk with {} syntax?
Tom Ellis
tom-lists-haskell-cafe-2023 at jaguarpaw.co.uk
Thu Nov 30 14:06:00 UTC 2023
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?
More information about the Haskell-Cafe
mailing list