Last active
April 30, 2020 19:35
-
-
Save lgastako/ce6627d75ef6202f8dfb35303888b84e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data MessageType | |
= Info | |
| Warning | |
| Error Int | |
deriving (Eq, Show) | |
type TimeStamp = Int | |
type LogMessage = Either String Message | |
data Message = Message | |
{ messageType :: MessageType | |
, timeStamp :: TimeStamp | |
, content :: String | |
} deriving (Eq, Show) | |
data Tree a | |
= Leaf | |
| Node (Tree a) a (Tree a) | |
deriving (Eq, Show) | |
insert :: Ord k => (a -> k) -> a -> Tree a -> Tree a | |
insert _ x Leaf = singleton x | |
insert k x (Node l y r) | |
| k x < k y = Node (insert k x l) y r | |
| otherwise = Node l y (insert k x r) | |
singleton :: a -> Tree a | |
singleton x = Node Leaf x Leaf | |
insertMsg :: Message -> Tree Message -> Tree Message | |
insertMsg = insert timeStamp | |
insertLogMessage :: LogMessage -> Tree Message -> Tree Message | |
insertLogMessage (Left _) t = t | |
insertLogMessage (Right m) t = insertMsg m t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment