[Haskell-cafe] Strange quirk with {} syntax?

J. Reinders jaro.reinders at gmail.com
Thu Nov 30 13:58:28 UTC 2023


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%5C%7B%5C%7D

> On 30 Nov 2023, at 14:46, Noon van der Silk <noonsilk at gmail.com> 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, ن
> 
> http://silky.github.io/
> 
> "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.




More information about the Haskell-Cafe mailing list