<br>Dan wrote:<br style="font-family: courier new,monospace;"><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote"><span style="font-family: courier new,monospace;">
height : Indexed Z -&gt; Nat</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">height B = Z</span><br></blockquote><br>The error message (which shouldn&#39;t involve panicking) tells you that you can&#39;t pattern match on the argument, because the type checker can&#39;t figure out if I is a valid constructor. In order to do this it would have to solve the unification problem 
<span style="font-family: courier new,monospace;">Z = plus n m,<span style="font-family: arial,sans-serif;"> which it can&#39;t.<br><br>The problem is that the index isn&#39;t a variable, which makes the unification problem too hard. The standard trick is to make the index a variable:
<br><br><span style="font-family: courier new,monospace;">data _==_ {A : Set}(x : A) : A -&gt; Set where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; refl : x == x
</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">height&#39; : {n : Nat} -&gt; Indexed n -&gt; n == Z -&gt; Nat</span>
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">height&#39; B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; refl = Z</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
height&#39; (I {Z}&nbsp;&nbsp; l r) refl = ?&nbsp; -- you forgot about this case</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">height&#39; (I {S n} l r) () &nbsp; &nbsp; &nbsp;&nbsp; -- impossible case
</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">height : Indexed Z -&gt; Nat</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">height i = height&#39; i refl</span><br style="font-family: courier new,monospace;"><br>In the I case (which you left out) we need to match on the size of the left sub-tree in order to be able to inspect the proof object. The reason your version of this approach didn&#39;t go through is that you need to 
<i>first</i> match on the tree and <i>then</i> on the proof object (otherwise we&#39;re back in the same situation as we started in). Pattern matching happens from left to right, so you need the proof argument to appear after the tree argument.
<br><br>/ Ulf<br></span></span>