<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Feb 28, 2015 at 5:07 AM, Roelof Wobben <span dir="ltr"><<a href="mailto:r.wobben@home.nl" target="_blank">r.wobben@home.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
<div><br>
That part I understand .<br>
<br>
it's more how I do it here :<br>
<br>
Lets say I have this : <br>
<br>
data MessageType = Info<br>
| Warning<br>
| Error Int<br>
deriving (Show, Eq)<br>
<br>
type TimeStamp = Int<br>
<br>
data LogMessage = LogMessage MessageType TimeStamp String<br>
| Unknown String<br>
deriving (Show, Eq)<br>
<br>
data MessageTree = Leaf<br>
| Node MessageTree LogMessage MessageTree<br>
deriving (Show, Eq)<br>
<br>
Now I have to put all the LogMessages in a binary tree.<br>
with this signature : insert :: LogMessage -> MessageTree ->
MessageTree<br>
<br>
I think I need recursion here but I still not see how I can make
the clauses. <br>
Normally you can say somethig like this [] -> 0 or 1 ->
but here it seems to be all seperate logMessages <br></div></div></blockquote><div><br></div><div>Whether you need recursion or not depends on where you're to insert the message. For instance, you could turn them into a list with:</div><div><br></div><div>insert message tree = Node tree message Leaf</div><div><br></div><div>Try drawing a few pictures of what that produces, and you'll see why it's probably not what you want.</div><div><br></div><div>You should be able to tell by looking at the MessageTree type that you have two cases: one where you're passed something matching a Node, and one where you're passed something that's just a Leaf. The latter can't be recursive, so it's going to terminate any recursion. Following the advice given to you for the Hanoi problem, try writing it first.</div><div><br></div><div>Then all you have to do is figure out how to handle the case where you're given a Node instead of a Leaf. Figuring out where in the MessageTree you want to insert the Logmessage will probably be required to do that.<br></div></div></div></div>