<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
&nbsp;<BR>
&gt;Someone correct <BR>&gt; me, if I'm mistaken <BR>
&gt; but what seems to cause the problem is that the pattern matcher <BR>&gt; needs constructors, so it can determine, whether a pattern can produce <BR>&gt; an input data.<BR>
Yes, I would agree with you on that. It seems correct to me.<BR>
&nbsp;<BR>
Angelos<BR><BR>
<BR>&nbsp;<BR>
<DIV>
<DIV id=SkyDrivePlaceholder></DIV>&gt; Date: Sat, 10 Mar 2012 12:45:07 +0100<BR>&gt; From: Micha-Schober@web.de<BR>&gt; To: beginners@haskell.org<BR>&gt; Subject: Re: [Haskell-beginners] Empty or Tree?<BR>&gt; <BR>&gt; &gt; But when I try to create a more generic code like this which could work<BR>&gt; &gt; with trees who don't have empty nodes in grandchild level :<BR>&gt; &gt;<BR>&gt; &gt; function Node a (Node b Tree Tree) (Node c Tree Tree )<BR>&gt; <BR>&gt; The problem is that 'Tree' is a type, not a constructor. Someone correct <BR>&gt; me, if I'm mistaken (this is my first post to the mailing-list, yieah <BR>&gt; :-)), but what seems to cause the problem is that the pattern matcher <BR>&gt; needs constructors, so it can determine, whether a pattern can produce <BR>&gt; an input data.<BR>&gt; <BR>&gt; There are several solutions. If you don't need the further subtrees, <BR>&gt; leave them fully unspecified via the underscore:<BR>&gt; <BR>&gt; function (Node a (Node b _ _) (Node c _ _)) = ...<BR>&gt; <BR>&gt; or you could give them variable names like this:<BR>&gt; <BR>&gt; function (Node a (Node b bl br) (Node c cl cr)) = ...<BR>&gt; <BR>&gt; where bl, br, cl, and cr are variables of the type Tree. However, what <BR>&gt; you might want to accomplish is a recursive function over the recursive <BR>&gt; type to get a fully generic code. This usually looks something like this:<BR>&gt; <BR>&gt; -- a generic recursive function<BR>&gt; cFunction :: Tree -&gt; a<BR>&gt; cFunction Empty = ...<BR>&gt; cFunction (Node i l r) = f i (cFunction l) (cFunction r)<BR>&gt; where<BR>&gt; f :: Integer -&gt; a -&gt; a -&gt; a<BR>&gt; f int recLeft recRight = ...<BR>&gt; <BR>&gt; Hope that helped.<BR>&gt; <BR>&gt; _______________________________________________<BR>&gt; Beginners mailing list<BR>&gt; Beginners@haskell.org<BR>&gt; http://www.haskell.org/mailman/listinfo/beginners<BR></DIV>                                               </div></body>
</html>