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