Re: Pattern synonym 'Required' constraints === Datatype Contexts(?)

ÉRDI Gergő <[email protected]> Fri, 12 Mar 2021 18:03:48 +0800 (+08)
Newsgroups gmane.comp.lang.haskell.glasgow.user
Message-ID <alpine.DEB.2.22.394.2103121802400.245873@galaxy>
On Thu, 11 Mar 2021, Richard Eisenberg wrote:

> You're right that these features sit in a similar space. The difference is that, with
> a pattern synonym, the required context might be useful. This is because pattern
> synonyms can perform computation (via view patterns), and this computation might
> plausibly require some class constraint. An easy example:
>       pattern Positive :: (Ord a, Num a) => a
> pattern Positive <- ((>0) -> True)

Heck, even just pattern matching on `0` (no view patterns) Requires the 
scrutinee to be both `Num` and `Eq`. To see why, ponder the inferred 
type of the following function:

```
foo 0 = True
foo _ = False
```
_______________________________________________
Glasgow-haskell-users mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users