summaryrefslogtreecommitdiff
path: root/src/Obs/Logging.idr
diff options
context:
space:
mode:
authorGreg Brown <greg.brown01@ed.ac.uk>2023-01-07 21:10:30 +0000
committerGreg Brown <greg.brown01@ed.ac.uk>2023-01-07 21:58:30 +0000
commitff65d1e285a97295708899bebdcc83ec214cd347 (patch)
tree7a786ef895ff2dea0ba31b3c7cd7397024214a10 /src/Obs/Logging.idr
parentf38761fd38207a6d9a6cc2134384cb7115a5e998 (diff)
Add containers types.
Containers are syntactic sugar. They are also completely untested.
Diffstat (limited to 'src/Obs/Logging.idr')
-rw-r--r--src/Obs/Logging.idr22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/Obs/Logging.idr b/src/Obs/Logging.idr
index 07060e6..1fc6454 100644
--- a/src/Obs/Logging.idr
+++ b/src/Obs/Logging.idr
@@ -43,8 +43,8 @@ record Message (ann : Type) where
bounds : Maybe Bounds
tags : List String
-pretty : Message ann -> Doc ann
-pretty msg =
+prettyMsg : Message ann -> Doc ann
+prettyMsg msg =
let leader =
hsep $
[ fill 6 (pretty (show msg.lvl) <+> colon) ] ++
@@ -107,7 +107,7 @@ discard (End v) = Just v
export
logToTerminal : Level -> Logging AnsiStyle a -> IO a
logToTerminal lvl (Cont msg l) = do
- () <- if msg.lvl <= lvl then putDoc (pretty msg) else pure ()
+ () <- if msg.lvl <= lvl then putDoc (prettyMsg msg) else pure ()
logToTerminal lvl l
logToTerminal lvl Abort = exitFailure
logToTerminal lvl (End v) = pure v
@@ -167,3 +167,19 @@ Loggable ann (Doc ann) where
export
Pretty x => Loggable ann x where
log lvl msg = log lvl $ pretty {ann = ann} msg
+
+-- Loggings ----------------------------------------------------------------------
+
+export
+mismatch : (expected, got : Doc ann) -> Logging ann a
+mismatch lhs rhs = fatal $
+ hang 2 (pretty "expected" <+> line <+> lhs) <+> comma <+> line <+>
+ hang 2 (pretty "got" <+> line <+> align rhs)
+
+export
+typeMismatch : Doc ann -> Doc ann -> Logging ann a
+typeMismatch lhs rhs = inScope "type mismatch" $ mismatch lhs rhs
+
+export
+universeMismatch : Doc ann -> Doc ann -> Logging ann a
+universeMismatch lhs rhs = inScope "universe mismatch" $ mismatch lhs rhs