在解释Persistent章节中的模板扩展时,Yesod书看起来像
<div id="register">
<div class="box">
<p>IP</p>
</div>
<div id="IP" class="box">
<p></p>
</div>
<div class="box">
<p>IS</p>
</div>
<div id="IS" class="box">
<p></p>
</div>
<div class="box">
<p>R0</p>
</div>
<div id="R0" class="box">
<p></p>
</div>
<div class="box">
<p>R1</p>
</div>
<div id="R1" class="box">
<p></p>
</div>
</div>
<div id="case">
<div id="0" class="box">
<input></input>
<p class="id">0</p>
</div>
<div id="1" class="box">
<input></input>
<p class="id">1</p>
</div>
<div id="2" class="box">
<input></input>
<p class="id">2</p>
</div>
<div id="3" class="box">
<input></input>
<p class="id">3</p>
</div>
<div id="4" class="box">
<input></input>
<p class="id">4</p>
</div>
<div id="5" class="box">
<input></input>
<p class="id">5</p>
</div>
<div id="6" class="box">
<input></input>
<p class="id">6</p>
</div>
<div id="7" class="box">
<input></input>
<p class="id">7</p>
</div>
<div id="8" class="box">
<input></input>
<p class="id">8</p>
</div>
<div id="9" class="box">
<input></input>
<p class="id">9</p>
</div>
<div id="10" class="box">
<input></input>
<p class="id">10</p>
</div>
<div id="11" class="box">
<input></input>
<p class="id">11</p>
</div>
<div id="12" class="box">
<input></input>
<p class="id">12</p>
</div>
<div id="13" class="box">
<input></input>
<p class="id">13</p>
</div>
<div id="14" class="box">
<input></input>
<p class="id">14</p>
</div>
<div id="15" class="box">
<p class="id">15</p>
<input></input>
</div>
</div>
<div id="instructions">
<p class="header">Instructions:</p>
<p class="info header">1-Byte Instructions</p>
<p class="info">0 = Halt</p>
<p class="info">1 = Add (R0 = R0 + R1)</p>
<p class="info">2 = Subtract (R0 = R0 - R1)</p>
<p class="info">3 = Increment R0 (R0 = R0 + 1)</p>
<p class="info">4 = Increment R1 (R1 = R1 + 1)</p>
<p class="info">5 = Decrement R0 (R0 = R0 - 1)</p>
<p class="info">6 = Decrement R1 (R1 = R1 - 1)</p>
<p class="info">7 = Ring Bell/Beep</p>
<p class="info header">2-Byte Instructions, value of the second Byte is called <data></p>
<p class="info">8 = Print <data></p>
<p class="info">9 = Load value at address <data> into R0</p>
<p class="info">10 = Load value at address <data> into R1</p>
<p class="info">11 = Store R0 into address <data></p>
<p class="info">12 = Store R1 into address <data></p>
<p class="info">13 = Jump to address <data></p>
<p class="info">14 = Jump to address <data> if R0 == 0</p>
<p class="info">15 = Jump to address <data> if R0 != 0</p>
</div>
<div id="output">
<p>Output:</p>
</div>
我不太确定如何阅读这个新类型声明:是
newtype Key Person = PersonKey (BackendKey SqlBackend)
已在其他地方定义的内容(不能
找到它的定义虽然)或PersonKey a
只是一个普通的
类型或值构造函数,如PersonKey
/ Just
/ Nothing
/ etc。 ?
答案 0 :(得分:1)
好的,首先简化一下,让我们假装说:
Left
在这种情况下,newtype KeyPerson = PersonKey (BackendKey SqlBackend)
将是“类型构造函数”,KeyPerson
将是“数据构造函数”。我们将在这里创建它们。 PersonKey
数据构造函数将保存类型为PersonKey
的值,该值需要存在于其他位置并从此处引用。
在这种情况下,我们通常是关联类型(也称为类型系列),这使得略微更复杂:BackendKey SqlBackend
意味着“我们正在定义关联的{{1}对于newtype Key Person
类型。但我们仍然像以前一样创建Key
数据构造函数。