<div dir="ltr">The required context on pattern synonyms isn't just useful, it's necessary.  Since arbitrary computation can happen in both the pattern matching and construction we need the context.<div>Take Richard's example, without the context on Positive we would infer the wrong type for any use of the Positive synonym.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Mar 11, 2021 at 7:09 AM Richard Eisenberg <<a href="mailto:rae@richarde.dev">rae@richarde.dev</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;">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:<div><br></div><div><div></div><blockquote type="cite"><div>pattern Positive :: (Ord a, Num a) => a</div><div>pattern Positive <- ((>0) -> True)</div></blockquote><div><br></div><div>Here, the required context is helpful. On the other hand, because matching against a data constructor never does computation, the constraints are never useful in this way.</div><div><br></div><div>Richard</div><div><br><blockquote type="cite"><div>On Mar 9, 2021, at 7:02 PM, Anthony Clayden <<a href="mailto:anthony_clayden@clear.net.nz" target="_blank">anthony_clayden@clear.net.nz</a>> wrote:</div><br><div><div dir="ltr">I must be slow on the uptake. I've just grokked this equivalence -- or is it? Consider<div><br></div><div>>    data Eq a => Set a = NilSet | ConsSet a (Set a)     -- from the Language report</div><div>></div><div>>    -- ConsSet :: forall a. Eq a => a -> Set a => Set a   -- inferred/per report</div><div>></div><div>>    <span style="font-family:Arial,Helvetica,sans-serif">--  equiv with Pattern syn 'Required' constraint</span></div>>    data Set' a = NilSet' | ConsSet' a (Set' a)     -- no DT context<br>><div>>    pattern ConsSetP :: (Eq a) => () => a -> (Set' a) -> (Set' a)<br>>    pattern ConsSetP x xs = ConsSet' x xs<br>><br><div>>    ffP ((ConsSet x xs), (ConsSetP y ys)) = (x, y)<br></div></div><div>></div><div>>    -- ffP :: forall {a} {b}. (Eq a, Eq b) => (Set a, Set' b) -> (a, b)   -- inferred</div><div><br></div><div>The signature decl for `ConsSetP` explicitly gives both the Required `(Eq a) =>` and Provided `() =>` constraints, but the Provided could be omitted, because it's empty. I get the same signature for both `ConsSetP` as `ConsSet` with the DT Context. Or is there some subtle difference?</div><div><br></div><div>This typing effect is what got DT Contexts called 'stupid theta' and deprecated/removed from the language standard. ("widely considered a mis-feature", as GHC is keen to tell me.) If there's no difference, why re-introduce the feature for Patterns? That is, why go to the bother of the double-context business, which looks weird, and behaves counter to usual signatures:</div><div><br></div><div>>    foo :: (Eq a) => (Show a) => a -> a</div><div>>    --   foo :: forall {a}. (Eq a, Show a) => a -> a     -- inferred</div><div><br></div><div>There is a slight difference possible with Pattern synonyms, compare:</div><div><br></div><div>>    pattern <span style="font-family:Arial,Helvetica,sans-serif">NilSetP :: (Eq a) => () => (Set' a)</span></div>>    pattern NilSetP = NilSet'<div>></div><div>>    -- NilSetP :: forall {a}. Eq a => Set' a             -- inferred</div><div>>    -- NilSet   :: forall {a}.      => Set a                   -- inferred/per report</div><div><br></div><div>Using `NilSetP` somewhere needs giving an explicit signature/otherwise your types are ambiguous; but arguably that's a better discipline than using `NilSet` and allowing a Set with non-comparable element types.</div><div><br></div><div>AntC</div></div>
_______________________________________________<br>Glasgow-haskell-users mailing list<br><a href="mailto:Glasgow-haskell-users@haskell.org" target="_blank">Glasgow-haskell-users@haskell.org</a><br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users</a><br></div></blockquote></div><br></div></div>_______________________________________________<br>
Glasgow-haskell-users mailing list<br>
<a href="mailto:Glasgow-haskell-users@haskell.org" target="_blank">Glasgow-haskell-users@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users</a><br>
</blockquote></div>