That part I understand .
it's more how I do it here :
Lets say I have this :
data MessageType = Info
| Warning
| Error Int
deriving (Show, Eq)
type TimeStamp = Int
data LogMessage = LogMessage MessageType TimeStamp String
| Unknown String
deriving (Show, Eq)
data MessageTree = Leaf
| Node MessageTree LogMessage MessageTree
deriving (Show, Eq)
Now I have to put all the LogMessages in a binary tree.
with this signature : insert :: LogMessage -> MessageTree -> MessageTree
I think I need recursion here but I still not see how I can make the clauses.
Normally you can say somethig like this [] -> 0 or 1 -> but here it seems to be all seperate logMessages
Roelof
Sumit Sahrawat, Maths & Computing, IIT (BHU) schreef op 28-2-2015 om 11:53:
Draw the trees, and then try to partition every node into (left, element, right).
For example, in your first example (Node leaf "msg 1" leaf), we get
Node "msg 1"├── leaf└── leafIn the second example,
Node "msg 1"├── leaf└── Node "msg 2" -- A sub-tree├── leaf└── leafNow, substituting a leaf with a Node in the above tree will lead to larger trees.
For another example, look here: http://en.wikipedia.org/wiki/Tagged_union#Examples
On 28 February 2015 at 14:10, Roelof Wobben <r.wobben@home.nl> wrote:
Hello,
I found out that for 1 item I can do this : node = Node leaf "msg 1" leaf
And for 2 items I can do this : node = Node leaf "msg1" (Node leaf "msg2" leaf)
But now I wonder how I can make this work with recursion. It seems that I keep the first 2 items and change the 3th one from leaf to another node
Roelof
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
--
Regards
Sumit Sahrawat
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe