<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
Repeated variables in patterns were allowed in Miranda, a predecessor of Haskell. In a lazy context there are interesting questions about how pattern matches fail, and in particular the point at which equality tests take place in matching a complex pattern.
This paper
<div><br>
</div>
<div>
<div style="display: block;">
<div style="-webkit-user-select: all; -webkit-user-drag: element; display: inline-block;" class="apple-rich-link" draggable="true" role="link" data-url="https://dl.acm.org/doi/pdf/10.1007/BF01887213">
<a style="border-radius:10px;font-family:-apple-system, Helvetica, Arial, sans-serif;display:block;-webkit-user-select:none;width:228px;user-select:none;-webkit-user-modify:read-only;user-modify:read-only;overflow:hidden;text-decoration:none;" class="lp-rich-link" rel="nofollow" href="https://dl.acm.org/doi/pdf/10.1007/BF01887213" dir="ltr" role="button" draggable="false" width="228">
<table style="table-layout:fixed;border-collapse:collapse;width:228px;background-color:#E5E6E9;font-family:-apple-system, Helvetica, Arial, sans-serif;" class="lp-rich-link-emailBaseTable" cellpadding="0" cellspacing="0" border="0" width="228">
<tbody>
<tr>
<td vertical-align="center" align="center"><img style="width:228px;filter:brightness(0.97);height:295px;" width="228" height="295" draggable="false" class="lp-rich-link-mediaImage" alt="preview.png" src="cid:ADE7BB75-2833-485E-98AB-34E5310082B0"></td>
</tr>
<tr>
<td vertical-align="center">
<table bgcolor="#E5E6E9" cellpadding="0" cellspacing="0" width="228" style="table-layout:fixed;font-family:-apple-system, Helvetica, Arial, sans-serif;background-color:rgba(229, 230, 233, 1);" class="lp-rich-link-captionBar">
<tbody>
<tr>
<td style="padding:8px 0px 8px 0px;" class="lp-rich-link-captionBar-textStackItem">
<div style="max-width:100%;margin:0px 16px 0px 16px;overflow:hidden;" class="lp-rich-link-captionBar-textStack">
<div style="word-wrap:break-word;font-weight:500;font-size:12px;overflow:hidden;text-overflow:ellipsis;text-align:left;" class="lp-rich-link-captionBar-textStack-topCaption-leading">
<a rel="nofollow" href="https://dl.acm.org/doi/pdf/10.1007/BF01887213" style="text-decoration: none" draggable="false"><font color="#272727" style="color: rgba(0, 0, 0, 0.847059);">BF01887213</font></a></div>
<div style="word-wrap:break-word;font-weight:400;font-size:11px;overflow:hidden;text-overflow:ellipsis;text-align:left;" class="lp-rich-link-captionBar-textStack-bottomCaption-leading">
<a rel="nofollow" href="https://dl.acm.org/doi/pdf/10.1007/BF01887213" style="text-decoration: none" draggable="false"><font color="#808080" style="color: rgba(0, 0, 0, 0.498039);">PDF Document ยท 1.5 MB</font></a></div>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</a></div>
</div>
</div>
<div><br>
</div>
<div>section 6.2 explains how these two definitions differ in meaning</div>
<div><br>
</div>
<div>g [x,x] = 37</div>
<div>g z = 42</div>
<div><br>
</div>
<div>h [x,y] = 37 , x=y</div>
<div>h z = 42</div>
<div><br>
</div>
<div>Simon<br id="lineBreakAtBeginningOfMessage">
<div><br>
<blockquote type="cite">
<div>On 6 May 2025, at 10:01, Serguey Zefirov <sergueyz@gmail.com> wrote:</div>
<br class="Apple-interchange-newline">
<div>
<div dir="ltr">
<div>There are artifacts of old Haskell standards that are a matching against integer value (2 + 2 = 5) and a matching against arithmetic expression (f (n+1) = f n).</div>
<div><br>
</div>
<div>Both are interesting in requiring a class over type to match.</div>
<div><br>
</div>
<div>f 10 = 11 has type f :: (Eq a1, Num a1, Num a2) => a1 -> a2</div>
<div><br>
</div>
<div>f (n+1) = f n has type f :: Integral t1 => t1 -> t2</div>
<div><br>
</div>
<div>In that vein it is possible to add non-linear patterns by adding an equality constraint on the non-linear matches.</div>
<div><br>
</div>
<div>E.g., f x x = x would have type f :: Eq a => a -> a -> a</div>
<div><br>
</div>
<div>For example:</div>
<div><br>
</div>
<div>data Logic = True | False | Not Logic | Or Logic Logic | And Logic Logic deriving Eq</div>
<div><br>
</div>
<div>simplify (And x x) = simplify x</div>
<div>simplify (Or x x) = simplify x</div>
<div>simplify (Not (Not x)) = simplify x</div>
<div>simplify x = x</div>
<div><br>
</div>
<div>Patterns like that are common in simplification/optimization rules. Also, by making them legal, it would be possible to use them in Template Haskell to make better embedded languages.</div>
<div><br>
</div>
<div>On the implementation side, it can be implemented much like the (n+k) pattern. I also think that pattern matching completeness checker should not change.</div>
<div><br>
</div>
<div>What would you say?</div>
</div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe<br>
Only members subscribed via the mailman list are allowed to post.</div>
</blockquote>
</div>
<br>
<div>
<div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
<div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
<div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
<div>Simon Thompson | Professor of Logic and Computation <br>
School of Computing | University of Kent | Canterbury, CT2 7NF, UK<br>
s.j.thompson@kent.ac.uk | M +44 7986 085754 | W www.cs.kent.ac.uk/~sjt</div>
</div>
</div>
</div>
</div>
<br>
</div>
</body>
</html>