Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- i have those data types.
- -- TimeStamp is an Int
- -- MessageType is not important for this question :-).
- data LogMessage = LogMessage MessageType TimeStamp String
- | Unknown String
- deriving (Show, Eq)
- data MessageTree = Leaf
- | Node MessageTree LogMessage MessageTree
- deriving (Show, Eq)
- {-
- the exercise is this:
- A MessageTree should be sorted by timestamp: that is, the timestamp
- of a LogMessage in any Node should be greater than all timestamps
- of any LogMessage in the left subtree, and less than all timestamps
- of any LogMessage in the right child.
- Unknown messages should not be stored in a MessageTree since
- they lack a timestamp.
- i need to create this function: -}
- insert :: LogMessage -> MessageTree -> MessageTree
- {-
- which inserts a new LogMessage into an existing MessageTree, producing
- a new MessageTree. insert may assume that it is given a
- sorted MessageTree, and must produce a new sorted MessageTree
- containing the new LogMessage in addition to the contents of the
- original MessageTree.
- However, note that if insert is given a LogMessage which is
- Unknown, it should return the MessageTree unchanged.
- can you please give me a hint?
- what i have done so far is this:
- -}
- insert :: LogMessage -> MessageTree -> MessageTree
- insert (Unknown _) m = m
- insert l Leaf = Node Leaf l Leaf
- {-
- but i can get a `insert` with a non empty MessageTree and i don't understand how to insert a new LogMessage to a non empty MessageTree.
- please do not post answers.
- just a hint how to proceed.
- thanks!
- -}
Advertisement
Add Comment
Please, Sign In to add comment