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

ÉRDI Gergő gergo at
Fri Mar 12 10:03:48 UTC 2021

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

More information about the Glasgow-haskell-users mailing list