This file is indexed.

/usr/share/doc/frown-doc/html/Manual005.html is in frown-doc 0.6.1-14.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="hevea 2.06">
<link rel="stylesheet" type="text/css" href="Manual.css">
<title>Tips and tricks</title>
</head>
<body >
<a href="Manual004.html"><img src="previous_motif.gif" alt="Previous"></a>
<a href="index.html"><img src="contents_motif.gif" alt="Up"></a>
<a href="Manual006.html"><img src="next_motif.gif" alt="Next"></a>
<hr>
<h1 id="sec36" class="chapter">Chapter 4  Tips and tricks</h1>
<h2 id="sec37" class="section">4.1  Irrefutable patterns</h2>
<p>
<a id="sec:irrefutable"></a>
</p><p>Irrefutable patterns on the RHS (<span style="font-family:monospace">VarParen.lg</span>):

<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  </span><span style="font-family:monospace"><span style="font-weight:bold">module</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">VarParen</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-weight:bold">where</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  </span><span style="font-family:monospace"><span style="font-weight:bold">import</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Result</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt; </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  </span><span style="font-family:monospace"><span style="font-weight:bold">newtype</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Tree</span></span><span style="font-family:monospace">                  =  </span><span style="font-family:monospace"><span style="font-style:italic">Node</span></span><span style="font-family:monospace"> [</span><span style="font-family:monospace"><span style="font-style:italic">Tree</span></span><span style="font-family:monospace">]</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;                                   </span><span style="font-family:monospace"><span style="font-weight:bold">deriving</span></span><span style="font-family:monospace"> (</span><span style="font-family:monospace"><span style="font-style:italic">Show</span></span><span style="font-family:monospace">)</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt; </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  %{</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt; </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  </span><span style="font-family:monospace"><span style="font-style:italic">Terminal</span></span><span style="font-family:monospace">                      =  </span><span style="font-family:monospace">’(’</span><span style="font-family:monospace"> | </span><span style="font-family:monospace">’)’</span><span style="font-family:monospace">;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt; </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  </span><span style="font-family:monospace"><span style="font-style:italic">Nonterminal</span></span><span style="font-family:monospace">                   =  paren {</span><span style="font-family:monospace"><span style="font-style:italic">Tree</span></span><span style="font-family:monospace">};</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt; </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  paren  {</span><span style="font-family:monospace"><span style="font-style:italic">Node</span></span><span style="font-family:monospace"> []}              :  ;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;         {</span><span style="font-family:monospace"><span style="font-style:italic">Node</span></span><span style="font-family:monospace"> (x : xs)}        |  paren {x}, </span><span style="font-family:monospace">’(’</span><span style="font-family:monospace">, paren {</span><span style="font-family:monospace"><span style="font-style:italic">Node</span></span><span style="font-family:monospace"> xs}, </span><span style="font-family:monospace">’)’</span><span style="font-family:monospace">;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt; </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  }%</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt; </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  frown ts                      =  fail "syntax error"</span></td></tr>
</table><p>

</TD></TR></TABLE><P>
</p>
<h2 id="sec38" class="section">4.2  Inherited attributes</h2>
<p>
<a id="sec:inherited"></a>
</p><p>Shows how to simulate inherited attributes: <span style="font-family:monospace">expr</span> has type <span style="font-family:monospace"><span style="font-style:italic">Integer</span></span><span style="font-family:monospace"> -&gt; (</span><span style="font-family:monospace"><span style="font-style:italic">Tree</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Integer</span></span><span style="font-family:monospace"></span><span style="font-family:monospace"><span style="font-style:italic">Integer</span></span><span style="font-family:monospace">)</span>, it takes the global minimum to the
rep-min tree (with all elements replaced by the minimum) and the local
minimum (<span style="font-family:monospace">RepMin.lg</span>).

<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  </span><span style="font-family:monospace"><span style="font-weight:bold">module</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">RepMin</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-weight:bold">where</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt; </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  </span><span style="font-family:monospace"><span style="font-weight:bold">data</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Tree</span></span><span style="font-family:monospace"> a    =  </span><span style="font-family:monospace"><span style="font-style:italic">Leaf</span></span><span style="font-family:monospace"> a | </span><span style="font-family:monospace"><span style="font-style:italic">Fork</span></span><span style="font-family:monospace"> (</span><span style="font-family:monospace"><span style="font-style:italic">Tree</span></span><span style="font-family:monospace"> a) (</span><span style="font-family:monospace"><span style="font-style:italic">Tree</span></span><span style="font-family:monospace"> a)</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;                    </span><span style="font-family:monospace"><span style="font-weight:bold">deriving</span></span><span style="font-family:monospace"> (</span><span style="font-family:monospace"><span style="font-style:italic">Show</span></span><span style="font-family:monospace">)</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt; </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  </span><span style="font-family:monospace"><span style="font-weight:bold">data</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Terminal</span></span><span style="font-family:monospace">  =  </span><span style="font-family:monospace"><span style="font-style:italic">Num</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Integer</span></span><span style="font-family:monospace"> | </span><span style="font-family:monospace"><span style="font-style:italic">LPar</span></span><span style="font-family:monospace"> | </span><span style="font-family:monospace"><span style="font-style:italic">RPar</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt; </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  %{</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt; </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  </span><span style="font-family:monospace"><span style="font-style:italic">Terminal</span></span><span style="font-family:monospace">      =  </span><span style="font-family:monospace"><span style="font-style:italic">Num</span></span><span style="font-family:monospace"> {</span><span style="font-family:monospace"><span style="font-style:italic">Integer</span></span><span style="font-family:monospace">}</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;                |  </span><span style="font-family:monospace"><span style="font-style:italic">LPar</span></span><span style="font-family:monospace">  as "("</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;                |  </span><span style="font-family:monospace"><span style="font-style:italic">RPar</span></span><span style="font-family:monospace">  as ")";</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt; </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  </span><span style="font-family:monospace"><span style="font-style:italic">Nonterminal</span></span><span style="font-family:monospace">   =  *  start  {</span><span style="font-family:monospace"><span style="font-style:italic">Tree</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Integer</span></span><span style="font-family:monospace">}</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;                |     expr   {</span><span style="font-family:monospace"><span style="font-style:italic">Integer</span></span><span style="font-family:monospace"> -&gt; (</span><span style="font-family:monospace"><span style="font-style:italic">Tree</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Integer</span></span><span style="font-family:monospace"></span><span style="font-family:monospace"><span style="font-style:italic">Integer</span></span><span style="font-family:monospace">)};</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt; </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  start { </span><span style="font-family:monospace"><span style="font-weight:bold">let</span></span><span style="font-family:monospace"> (t, m) = f m </span><span style="font-family:monospace"><span style="font-weight:bold">in</span></span><span style="font-family:monospace"> t }</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;    : expr {f};</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt; </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  expr { \ m -&gt; (</span><span style="font-family:monospace"><span style="font-style:italic">Leaf</span></span><span style="font-family:monospace"> m, i) }</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;    :  </span><span style="font-family:monospace"><span style="font-style:italic">Num</span></span><span style="font-family:monospace"> {i};</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  expr { \ m -&gt; </span><span style="font-family:monospace"><span style="font-weight:bold">let</span></span><span style="font-family:monospace">  { (tl, ml)  =  l m</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;                     ; (tr, mr)  =  r m }</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;                </span><span style="font-family:monospace"><span style="font-weight:bold">in</span></span><span style="font-family:monospace"> (</span><span style="font-family:monospace"><span style="font-style:italic">Fork</span></span><span style="font-family:monospace"> tl tr, ml ‘min‘ mr) }</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;    :  expr {l}, "(", expr {r}, ")";</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt; </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  }%</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt; </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  frown ts                      =  fail "syntax error"</span></td></tr>
</table><p>

</TD></TR></TABLE><P>
!avoid layout-sensitive code!</p>
<h2 id="sec39" class="section">4.3  Dealing with conflicts</h2>
<p>
<a id="sec:conflicts"></a>

<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">&gt;  many’ x : many x;
</span></td></tr>
</table><p>

</TD></TR></TABLE><P>
</p>
<h2 id="sec40" class="section">4.4  Multiple attributes</h2>
<p>
<a id="sec:multattr"></a>
</p>
<hr>
<a href="Manual004.html"><img src="previous_motif.gif" alt="Previous"></a>
<a href="index.html"><img src="contents_motif.gif" alt="Up"></a>
<a href="Manual006.html"><img src="next_motif.gif" alt="Next"></a>
</body>
</html>