<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Why does only tr2 work, although the only difference between tr1 and tr2 is the order of arguments?<div><br></div><div><div><font class="Apple-style-span" face="Courier">import Data.Tree (Tree(..))</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">data Type a where Tree :: Type a -> Type (Tree a)</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="Courier">                </font></span><font class="Apple-style-span" face="Courier"> Int :: Type Int</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="Courier">                </font></span><font class="Apple-style-span" face="Courier"> String :: Type String</font></div><div><font class="Apple-style-span" face="Courier"><span class="Apple-style-span" style="white-space: pre;"><br></span></font></div><div><font class="Apple-style-span" face="Courier">type Traversal1 = forall a.a -> Type a -> a</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier"><div>type Traversal2 = forall a.Type a -> a -> a</div><div><br></div></font></div><div><font class="Apple-style-span" face="Courier">tr1 :: Traversal1</font></div><div><font class="Apple-style-span" face="Courier">tr1 (Node _ (t:_)) (Tree Int) = Node 1 [t]</font></div><div><font class="Apple-style-span" face="Courier">tr1 n Int = n+n</font></div><div><font class="Apple-style-span" face="Courier">tr1 s String</font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="Courier">                </font></span><font class="Apple-style-span" face="Courier"> = s++s</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">tr2 :: Traversal2</font></div><div><font class="Apple-style-span" face="Courier">tr2 (Tree Int) (Node _ (t:_)) = Node 1 [t]</font></div><div><font class="Apple-style-span" face="Courier">tr2 Int n = n+n</font></div><div><font class="Apple-style-span" face="Courier">tr2 String s</font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="Courier">                </font></span><font class="Apple-style-span" face="Courier"> = s++s</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div></div><div><div><span class="Apple-style-span" style="font-family: Courier; "> Couldn't match expected type `a' against inferred type `Tree Int'</span></div><div><font class="Apple-style-span" face="Courier"> `a' is a rigid type variable bound by</font></div><div><font class="Apple-style-span" face="Courier"> the type signature for `tr1' at tratest.hs:9:25</font></div><div><font class="Apple-style-span" face="Courier"> In the pattern: Node _ (t : _)</font></div><div><font class="Apple-style-span" face="Courier"> In the definition of `tr1':</font></div><div><font class="Apple-style-span" face="Courier"> tr1 (Node _ (t : _)) (Tree Int) = Node 1 [t]</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier"><br></font></div></div></body></html>