Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- qLog :: String -> String -> IO ()
- qLog l msg = log' "" msg where
- log' "I" msg = infoM "" msg
- log' "D" msg = debugM "" msg
- log' "E" msg = errorM "" msg
- log' "W" msg = warningM "" msg
- log' _ msg = infoM "" msg
- λ> qlog "D" "Thing!"
- [DEBUG::2017-01-18 20:38:19 EST] Thing!
- λ> qlog "I" "Thing!"
- [INFO::2017-01-18 20:38:19 EST] Thing!
- λ> qlog "Thing!"
- [INFO::2017-01-18 20:38:19 EST] Thing!
- qLog2 :: Maybe String -> String -> IO ()
- qLog2 l msg = case l msg of
- (Just "D") msg -> debugM "" msg
- (Just "I") msg -> infoM "" msg
- Nothing msg -> infoM "" msg
- qLog3 :: Maybe String -> String -> IO ()
- qLog3 l msg
- | Just "D" msg = debugM "" msg
- | Just "I" msg = infoM "" msg
- | Nothing msg = infoM "" msg
- qLog4 "D" msg = debugM "" msg
- qLog4 "I" msg = infoM "" msg
- qLog4 msg = infoM "" msg
- Equations for ‘qLog4’ have different numbers of arguments
- qLog2 :: Maybe String -> String -> IO ()
- qLog2 l msg =
- case l of
- Just "D" -> debugM "" msg
- Just "I" -> infoM "" msg
- Nothing -> infoM "" msg
- qLog :: Maybe String -> String -> IO ()
- qLog l msg = case l of
- Just "D" -> debugM "" msg
- Just "I" -> infoM "" msg
- -- etc.
- Nothing -> infoM "" msg
- -- Feel free to use less terse names.
- data LogLevel = D | I | W | E
- deriving (Eq, Show)
- qLog :: Maybe LogLevel -> String -> IO ()
- qLog l msg = case l of
- Just D -> debugM "" msg
- Just I -> infoM "" msg
- Just W -> warningM "" msg
- Just E -> errorM "" msg
- Nothing -> infoM "" msg
- -- I added a few superflous parentheses to emphasise what is going on.
- qLog :: Maybe LogLevel -> String -> IO ()
- qLog ml msg = case ml of
- Just l -> (fLog l) "" msg
- Nothing -> infoM "" msg
- where
- fLog :: LogLevel -> (String -> String -> IO ())
- fLog l = case l of
- D -> debugM
- I -> infoM
- W -> warningM
- E -> errorM
- GHCi> :t maybe
- maybe :: b -> (a -> b) -> Maybe a -> b
- -- There are also some superflous parentheses here.
- qLog :: Maybe LogLevel -> String -> IO ()
- qLog ml msg = (maybe infoM fLog ml) "" msg
- where
- fLog :: LogLevel -> (String -> String -> IO ())
- fLog l = case l of
- D -> debugM
- I -> infoM
- W -> warningM
- E -> errorM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement