<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 -- my apologies. Here is the accepted proposal: <a href="https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0042-bidir-constr-sigs.rst" class="">https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0042-bidir-constr-sigs.rst</a><div class=""><br class=""></div><div class="">Richard<br class=""><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Oct 5, 2021, at 12:38 PM, David Feuer <<a href="mailto:david.feuer@gmail.com" class="">david.feuer@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="auto" class="">To be clear, the proposal to allow different constraints was accepted, but integrating it into the current, incredibly complex, code was well beyond the limited abilities of the one person who made an attempt. Totally severing pattern synonyms from constructor synonyms (giving them separate namespaces) would be a much simpler design.</div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 5, 2021, 12:33 PM Richard Eisenberg <<a href="mailto:lists@richarde.dev" class="">lists@richarde.dev</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space" class=""><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Oct 3, 2021, at 5:38 AM, Anthony Clayden <<a href="mailto:anthony.d.clayden@gmail.com" target="_blank" rel="noreferrer" class="">anthony.d.clayden@gmail.com</a>> wrote:</div><div class=""><div dir="ltr" class=""><div class=""><font face="arial, sans-serif" class=""><br class=""></font></div><div class=""><font face="arial, sans-serif" class="">> pattern SmartConstr :: Ord a => () => ...</font></div><div class=""><font face="arial, sans-serif" class=""><br class=""></font></div><div class=""><font face="arial, sans-serif" class="">Seems to mean:</font></div><div class=""><font face="arial, sans-serif" class=""><br class=""></font></div><div class=""><font face="arial, sans-serif" class="">* Required constraint is Ord a -- fine, for building</font></div></div></div></blockquote><div class=""><br class=""></div><div class="">Yes.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><font face="arial, sans-serif" class="">* Provided constraint is Ord a -- why? for matching/consuming</font></div></div></div></blockquote><div class=""><br class=""></div><div class="">No. Your signature specified that there are no provided constraints: that's your ().</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><font face="arial, sans-serif" class=""><br class=""></font></div><div class=""><font face="arial, sans-serif" class="">I'm using `SmartConstr` with some logic inside it to validate/build a well-behaved data structure. But this is an ordinary H98 datatype, not a GADT.</font></div></div></div></blockquote><div class=""><br class=""></div><div class="">I believe there is no way to have provided constraints in Haskell98. You would need either GADTs or higher-rank types.</div><br class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class=""><font face="arial, sans-serif" class="">This feels a lot like one of the things that's wrong with 'stupid theta' datatype contexts.</font></div></div></blockquote><div class=""><br class=""></div><div class="">You're onto something here. Required constraints are very much like the stupid theta datatype contexts. But, unlike the stupid thetas, required constraints are sometimes useful: they might be needed in order to, say, call a function in a view pattern.</div><div class=""><br class=""></div><div class="">For example:</div><div class=""><br class=""></div><div class=""></div><blockquote type="cite" class=""><div class="">checkLT5AndReturn :: (Ord a, Num a) => a -> (Bool, a)</div><div class="">checkLT5AndReturn x = (x < 5, x)</div><div class=""><br class=""></div><div class="">pattern LessThan5 :: (Ord a, Num a) => a -> a</div><div class="">pattern LessThan5 x <- ( checkLT5AndReturn -> (True, x) )</div></blockquote><div class=""><br class=""></div><div class="">My view pattern requires (Ord a, Num a), and so I must declare these as required constraints in the pattern synonym type. Because vanilla data constructors never do computation, any required constraints for data constructors are always useless.</div><br class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class=""><font face="arial, sans-serif" class="">For definiteness, the use case is a underlying non-GADT constructor for a BST</font></div><div class=""><font face="arial, sans-serif" class=""><br class=""></font></div><div class=""><font face="arial, sans-serif" class="">> Node :: Tree a -> a -> Tree a -> Tree a</font></div><div class=""><font face="arial, sans-serif" class="">></font></div><div class=""><font face="arial, sans-serif" class="">> pattern SmartNode :: Ord a => () => Tree a -> a -> Tree a -> Tree a</font></div><div class=""><font face="arial, sans-serif" class=""><br class=""></font></div><div class=""><font face="arial, sans-serif" class="">with the usual semantics that the left Tree holds elements less than this node. Note it's the same `a` with the same `Ord a` 'all the way down' the Tree.</font></div></div></blockquote><div class=""><br class=""></div><div class="">Does SmartNode need Ord a to match? Or just to produce a node? It seems that Ord a is used only for production, not for matching. This suggests that you want a separate smartNode function (not a pattern synonym) and to have no constraints on the pattern synonym, which can be unidirectional (that is, work only as a pattern, not as an expression).</div><div class=""><br class=""></div><div class="">It has been mooted to allow pattern synonyms to have two types: one when used as a pattern and a different one when used as an expression. That might work for you here: you want SmartNode to have no constraints as a pattern, but an Ord a constraint as an expression. At the time, the design with two types was considered too complicated and abandoned.</div><div class=""><br class=""></div><div class="">Does this help?</div><div class=""><br class=""></div><div class="">Richard</div></div></div>_______________________________________________<br class="">
Glasgow-haskell-users mailing list<br class="">
<a href="mailto:Glasgow-haskell-users@haskell.org" target="_blank" rel="noreferrer" class="">Glasgow-haskell-users@haskell.org</a><br class="">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users" rel="noreferrer noreferrer" target="_blank" class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></div></div></body></html>