<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">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 class=""><br class=""></div><div class=""><div class=""></div><blockquote type="cite" class=""><div class="">pattern Positive :: (Ord a, Num a) => a</div><div class="">pattern Positive <- ((>0) -> True)</div></blockquote><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">Richard</div><div><br class=""><blockquote type="cite" class=""><div class="">On Mar 9, 2021, at 7:02 PM, Anthony Clayden <<a href="mailto:anthony_clayden@clear.net.nz" class="">anthony_clayden@clear.net.nz</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I must be slow on the uptake. I've just grokked this equivalence -- or is it? Consider<div class=""><br class=""></div><div class="">> data Eq a => Set a = NilSet | ConsSet a (Set a) -- from the Language report</div><div class="">></div><div class="">> -- ConsSet :: forall a. Eq a => a -> Set a => Set a -- inferred/per report</div><div class="">></div><div class="">> <span style="font-family:Arial,Helvetica,sans-serif" class="">-- equiv with Pattern syn 'Required' constraint</span></div>> data Set' a = NilSet' | ConsSet' a (Set' a) -- no DT context<br class="">><div class="">> pattern ConsSetP :: (Eq a) => () => a -> (Set' a) -> (Set' a)<br class="">> pattern ConsSetP x xs = ConsSet' x xs<br class="">><br class=""><div class="">> ffP ((ConsSet x xs), (ConsSetP y ys)) = (x, y)<br class=""></div></div><div class="">></div><div class="">> -- ffP :: forall {a} {b}. (Eq a, Eq b) => (Set a, Set' b) -> (a, b) -- inferred</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">> foo :: (Eq a) => (Show a) => a -> a</div><div class="">> -- foo :: forall {a}. (Eq a, Show a) => a -> a -- inferred</div><div class=""><br class=""></div><div class="">There is a slight difference possible with Pattern synonyms, compare:</div><div class=""><br class=""></div><div class="">> pattern <span style="font-family:Arial,Helvetica,sans-serif" class="">NilSetP :: (Eq a) => () => (Set' a)</span></div>> pattern NilSetP = NilSet'<div class="">></div><div class="">> -- NilSetP :: forall {a}. Eq a => Set' a -- inferred</div><div class="">> -- NilSet :: forall {a}. => Set a -- inferred/per report</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">AntC</div></div>
_______________________________________________<br class="">Glasgow-haskell-users mailing list<br class=""><a href="mailto:Glasgow-haskell-users@haskell.org" class="">Glasgow-haskell-users@haskell.org</a><br class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users<br class=""></div></blockquote></div><br class=""></div></body></html>