@@ -427,7 +427,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
427427 ]
428428 goSimple (ErrorParsingExterns err) =
429429 paras [ lineWithLevel "parsing externs files: "
430− , indent . prettyPrintParseError $ err
430+ , prettyPrintParseError err
431431 ]
432432 goSimple (ErrorParsingFFIModule path) =
433433 paras [ line "Unable to parse module from FFI file: "
@@ -435,7 +435,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
435435 ]
436436 goSimple (ErrorParsingModule err) =
437437 paras [ line "Unable to parse module: "
438− , indent . prettyPrintParseError $ err
438+ , prettyPrintParseError err
439439 ]
440440 goSimple (MissingFFIModule mn) =
441441 line $ "Missing FFI implementations for module " ++ runModuleName mn
@@ -444,8 +444,9 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
444444 , indent . line $ path
445445 ]
446446 goSimple (MultipleFFIModules mn paths) =
447− paras $ [ line $ "Multiple FFI implementations have been provided for module " ++ runModuleName mn ++ ": " ]
448− ++ map (indent . line) paths
447+ paras [ line $ "Multiple FFI implementations have been provided for module " ++ runModuleName mn ++ ": "
448+ , indent . paras $ map line paths
449+ ]
449450 goSimple (InvalidExternsFile path) =
450451 paras [ line "Externs file is invalid: "
451452 , indent . line $ path
@@ -462,11 +463,11 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
462463 line "Overlapping names in let binding."
463464 goSimple (InfiniteType ty) =
464465 paras [ line "An infinite type was inferred for an expression: "
465− , indent $ line $ prettyPrintType ty
466+ , indent $ typeAsBox ty
466467 ]
467468 goSimple (InfiniteKind ki) =
468469 paras [ line "An infinite kind was inferred for a type: "
469− , indent $ line $ prettyPrintKind ki
470+ , indent $ kindAsBox ki
470471 ]
471472 goSimple (MultipleFixities name) =
472473 line $ "Multiple fixity declarations for " ++ showIdent name
@@ -475,8 +476,9 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
475476 goSimple (OrphanFixityDeclaration op) =
476477 line $ "Orphan fixity declaration for " ++ show op
477478 goSimple (RedefinedModule name filenames) =
478− paras $ line ("Module " ++ runModuleName name ++ " has been defined multiple times:")
479− : map (indent . line . displaySourceSpan) filenames
479+ paras [ line ("Module " ++ runModuleName name ++ " has been defined multiple times:")
480+ , indent . paras $ map (line . displaySourceSpan) filenames
481+ ]
480482 goSimple (RedefinedIdent name) =
481483 line $ "Name " ++ showIdent name ++ " has been defined multiple times"
482484 goSimple (UnknownModule mn) =
@@ -548,43 +550,60 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
548550 goSimple (EscapedSkolem binding) =
549551 paras $ [ line "A type variable has escaped its scope." ]
550552 <> foldMap (\expr -> [ line "Relevant expression: "
551− , indent $ line $ prettyPrintValue expr
553+ , indent $ prettyPrintValue expr
552554 ]) binding
553555 goSimple (TypesDoNotUnify t1 t2)
554556 = paras [ line "Cannot unify type"
555− , indent $ line $ prettyPrintType t1
557+ , indent $ typeAsBox t1
556558 , line "with type"
557− , indent $ line $ prettyPrintType t2
559+ , indent $ typeAsBox t2
558560 ]
559561 goSimple (KindsDoNotUnify k1 k2) =
560562 paras [ line "Cannot unify kind"
561− , indent $ line $ prettyPrintKind k1
563+ , indent $ kindAsBox k1
562564 , line "with kind"
563− , indent $ line $ prettyPrintKind k2
565+ , indent $ kindAsBox k2
564566 ]
565567 goSimple (ConstrainedTypeUnified t1 t2) =
566568 paras [ line "Cannot unify constrained type"
567− , indent $ line $ prettyPrintType t1
569+ , indent $ typeAsBox t1
568570 , line "with type"
569− , indent $ line $ prettyPrintType t2
571+ , indent $ typeAsBox t2
570572 ]
571573 goSimple (OverlappingInstances nm ts (d : ds)) =
572− paras [ line $ "Overlapping instances found for " ++ showQualified runProperName nm ++ " " ++ unwords (map prettyPrintTypeAtom ts) ++ ":"
574+ paras [ line "Overlapping instances found for"
575+ , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
576+ , Box.vcat Box.left (map typeAtomAsBox ts)
577+ ]
578+ , line "The following instances were found:"
573579 , indent $ paras (line (showQualified showIdent d ++ " (chosen)") : map (line . showQualified showIdent) ds)
574580 ]
575581 goSimple OverlappingInstances{} = error "OverlappingInstances: empty instance list"
576582 goSimple (NoInstanceFound nm ts) =
577− line $ "No instance found for " ++ showQualified runProperName nm ++ " " ++ unwords (map prettyPrintTypeAtom ts)
583+ paras [ line "No instance found for"
584+ , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
585+ , Box.vcat Box.left (map typeAtomAsBox ts)
586+ ]
587+ ]
578588 goSimple (PossiblyInfiniteInstance nm ts) =
579− line $ "Instance for " ++ showQualified runProperName nm ++ " " ++ unwords (map prettyPrintTypeAtom ts) ++ " is possibly infinite."
589+ paras [ line "Instance for"
590+ , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
591+ , Box.vcat Box.left (map typeAtomAsBox ts)
592+ ]
593+ , line "is possibly infinite."
594+ ]
580595 goSimple (CannotDerive nm ts) =
581− line $ "Cannot derive " ++ showQualified runProperName nm ++ " instance for " ++ unwords (map prettyPrintTypeAtom ts)
596+ paras [ line "Cannot derive an instance for"
597+ , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
598+ , Box.vcat Box.left (map typeAtomAsBox ts)
599+ ]
600+ ]
582601 goSimple (CannotFindDerivingType nm) =
583602 line $ "Cannot derive instance, because the type declaration for " ++ runProperName nm ++ " could not be found."
584603 goSimple (DuplicateLabel l expr) =
585604 paras $ [ line $ "Duplicate label " ++ show l ++ " in row." ]
586605 <> foldMap (\expr' -> [ line "Relevant expression: "
587− , indent $ line $ prettyPrintValue expr'
606+ , indent $ prettyPrintValue expr'
588607 ]) expr
589608 goSimple (DuplicateTypeArgument name) =
590609 line $ "Duplicate type argument " ++ show name
@@ -600,29 +619,40 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
600619 line $ "Member " ++ showIdent ident ++ " is not a member of the class being instantiated"
601620 goSimple (ExpectedType ty kind) =
602621 paras [ line "In a type-annotated expression x :: t, the type t must have kind *."
603− , line $ "The error arises from the type " ++ prettyPrintType ty ++ " having the kind " ++ prettyPrintKind kind ++ " instead."
622+ , line "The error arises from the type"
623+ , indent $ typeAsBox ty
624+ , line "having the kind"
625+ , indent $ kindAsBox kind
626+ , line "instead."
604627 ]
605628 goSimple (IncorrectConstructorArity nm) =
606629 line $ "Wrong number of arguments to constructor " ++ showQualified runProperName nm
607630 goSimple SubsumptionCheckFailed = line "Unable to check type subsumption"
608631 goSimple (ExprDoesNotHaveType expr ty) =
609632 paras [ line "Expression"
610− , indent $ line $ prettyPrintValue expr
633+ , indent $ prettyPrintValue expr
611634 , line "does not have type"
612− , indent $ line $ prettyPrintType ty
635+ , indent $ typeAsBox ty
613636 ]
614637 goSimple (PropertyIsMissing prop row) =
615− line $ "Row " ++ prettyPrintRow row ++ " lacks required property " ++ show prop
638+ paras [ line "Row"
639+ , indent $ prettyPrintRowWith '(' ')' row
640+ , line $ "lacks required property " ++ show prop
641+ ]
616642 goSimple (CannotApplyFunction fn arg) =
617643 paras [ line "Cannot apply function of type"
618− , indent $ line $ prettyPrintType fn
644+ , indent $ typeAsBox fn
619645 , line "to argument"
620− , indent $ line $ prettyPrintValue arg
646+ , indent $ prettyPrintValue arg
621647 ]
622648 goSimple TypeSynonymInstance =
623649 line "Type synonym instances are disallowed"
624650 goSimple (OrphanInstance nm cnm ts) =
625− paras [ line $ "Instance " ++ showIdent nm ++ " for " ++ showQualified runProperName cnm ++ " " ++ unwords (map prettyPrintTypeAtom ts) ++ " is an orphan instance."
651+ paras [ line $ "Instance " ++ showIdent nm ++ " for "
652+ , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName cnm)
653+ , Box.vcat Box.left (map typeAtomAsBox ts)
654+ ]
655+ , line "is an orphan instance."
626656 , line "An orphan instance is an instance which is defined in neither the class module nor the data type module."
627657 , line "Consider moving the instance, if possible, or using a newtype wrapper."
628658 ]
@@ -630,7 +660,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
630660 line "Newtypes must define a single constructor with a single argument"
631661 goSimple (InvalidInstanceHead ty) =
632662 paras [ line "Invalid type in class instance head:"
633− , indent $ line $ prettyPrintType ty
663+ , indent $ typeAsBox ty
634664 ]
635665 goSimple (TransitiveExportError x ys) =
636666 paras $ line ("An export for " ++ prettyPrintExport x ++ " requires the following to also be exported: ")
@@ -643,15 +673,17 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
643673 line $ "Type variable '" ++ tv ++ "' was declared but not used"
644674 goSimple (ClassOperator className opName) =
645675 paras [ line $ "Class '" ++ runProperName className ++ "' declares operator " ++ showIdent opName ++ "."
646− , indent $ line "This may be disallowed in the future - consider declaring a named member in the class and making the operator an alias:"
647− , indent $ line $ showIdent opName ++ " = someMember"
676+ , line "This may be disallowed in the future - consider declaring a named member in the class and making the operator an alias:"
677+ , indent . line $ showIdent opName ++ " = someMember"
648678 ]
649679 goSimple (MisleadingEmptyTypeImport mn name) =
650680 line $ "Importing type " ++ runProperName name ++ "(..) from " ++ runModuleName mn ++ " is misleading as it has no exported data constructors"
651681 goSimple (ImportHidingModule name) =
652682 line $ "Attempted to hide module " ++ runModuleName name ++ " in import expression, this is not permitted"
653683 goSimple (WildcardInferredType ty) =
654− line $ "The wildcard type definition has the inferred type " ++ prettyPrintType ty
684+ paras [ line "The wildcard type definition has the inferred type "
685+ , indent $ typeAsBox ty
686+ ]
655687 goSimple (NotExhaustivePattern bs b) =
656688 paras $ [ line "A case expression could not be determined to cover all inputs."
657689 , line "The following additional cases are required to cover all inputs:\n"
@@ -669,18 +701,18 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
669701 ]
670702 go (NotYetDefined names err) =
671703 paras [ line $ "The following are not yet defined here: " ++ intercalate ", " (map showIdent names) ++ ":"
672− , indent $ go err
704+ , go err
673705 ]
674706 go (ErrorUnifyingTypes t1 t2 err) =
675707 paras [ lineWithLevel "unifying type "
676− , indent $ line $ prettyPrintType t1
708+ , indent $ typeAsBox t1
677709 , line "with type"
678− , indent $ line $ prettyPrintType t2
710+ , indent $ typeAsBox t2
679711 , go err
680712 ]
681713 go (ErrorInExpression expr err) =
682714 paras [ lineWithLevel "in expression:"
683− , indent $ line $ prettyPrintValue expr
715+ , indent $ prettyPrintValue expr
684716 , go err
685717 ]
686718 go (ErrorInModule mn err) =
@@ -689,39 +721,42 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
689721 ]
690722 go (ErrorInSubsumption t1 t2 err) =
691723 paras [ lineWithLevel "checking that type "
692− , indent $ line $ prettyPrintType t1
724+ , indent $ typeAsBox t1
693725 , line "subsumes type"
694− , indent $ line $ prettyPrintType t2
726+ , indent $ typeAsBox t2
695727 , go err
696728 ]
697− go (ErrorInInstance name ts err) =
698− paras [ lineWithLevel $ "in type class instance " ++ showQualified runProperName name ++ " " ++ unwords (map prettyPrintTypeAtom ts) ++ ":"
729+ go (ErrorInInstance nm ts err) =
730+ paras [ lineWithLevel "in type class instance"
731+ , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
732+ , Box.vcat Box.left (map typeAtomAsBox ts)
733+ ]
699734 , go err
700735 ]
701736 go (ErrorCheckingKind ty err) =
702737 paras [ lineWithLevel "checking kind of type "
703− , indent $ line $ prettyPrintType ty
738+ , indent $ typeAsBox ty
704739 , go err
705740 ]
706741 go (ErrorInferringType expr err) =
707742 paras [ lineWithLevel "inferring type of value "
708− , indent $ line $ prettyPrintValue expr
743+ , indent $ prettyPrintValue expr
709744 , go err
710745 ]
711746 go (ErrorCheckingType expr ty err) =
712747 paras [ lineWithLevel "checking that value "
713− , indent $ line $ prettyPrintValue expr
748+ , indent $ prettyPrintValue expr
714749 , line "has type"
715− , indent $ line $ prettyPrintType ty
750+ , indent $ typeAsBox ty
716751 , go err
717752 ]
718753 go (ErrorInApplication f t a err) =
719754 paras [ lineWithLevel "applying function"
720− , indent $ line $ prettyPrintValue f
755+ , indent $ prettyPrintValue f
721756 , line "of type"
722− , indent $ line $ prettyPrintType t
757+ , indent $ typeAsBox t
723758 , line "to argument"
724− , indent $ line $ prettyPrintValue a
759+ , indent $ prettyPrintValue a
725760 , go err
726761 ]
727762 go (ErrorInDataConstructor nm err) =
@@ -758,7 +793,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
758793 ]
759794 go (PositionedError srcSpan err) =
760795 paras [ lineWithLevel $ "at " ++ displaySourceSpan srcSpan ++ ":"
761− , indent $ go err
796+ , go err
762797 ]
763798 go (SimpleErrorWrapper sem) = goSimple sem
764799
@@ -842,11 +877,11 @@ prettyPrintMultipleWarnings full = renderBox . prettyPrintMultipleWarningsBox fu
842877
843878-- | Pretty print warnings as a Box
844879prettyPrintMultipleWarningsBox :: Bool -> MultipleErrors -> Box.Box
845−prettyPrintMultipleWarningsBox full = flip evalState M.empty . prettyPrintMultipleErrorsWith Warning "Warning found:" "Multiple warnings found:" full
880+prettyPrintMultipleWarningsBox full = flip evalState M.empty . prettyPrintMultipleErrorsWith Warning "Warning found:" "Warning" full
846881
847882-- | Pretty print errors as a Box
848883prettyPrintMultipleErrorsBox :: Bool -> MultipleErrors -> Box.Box
849−prettyPrintMultipleErrorsBox full = flip evalState M.empty . prettyPrintMultipleErrorsWith Error "Error found:" "Multiple errors found:" full
884+prettyPrintMultipleErrorsBox full = flip evalState M.empty . prettyPrintMultipleErrorsWith Error "Error found:" "Error" full
850885
851886prettyPrintMultipleErrorsWith :: Level -> String -> String -> Bool -> MultipleErrors -> State UnknownMap Box.Box
852887prettyPrintMultipleErrorsWith level intro _ full (MultipleErrors [e]) = do
@@ -856,11 +891,12 @@ prettyPrintMultipleErrorsWith level intro _ full (MultipleErrors [e]) = do
856891 , result
857892 ]
858893prettyPrintMultipleErrorsWith level _ intro full (MultipleErrors es) = do
859− result <- forM es $ liftM (Box.moveRight 2) . prettyPrintSingleError full level
860− return $
861− Box.vcat Box.left [ Box.text intro
862− , Box.vsep 1 Box.left result
863− ]
894+ result <- forM es $ prettyPrintSingleError full level
895+ return $ Box.vsep 1 Box.left $ concat $ zipWith withIntro [1 :: Int ..] result
896+ where
897+ withIntro i err = [ Box.text (intro ++ " " ++ show i ++ " of " ++ show (length es) ++ ":")
898+ , Box.moveRight 2 err
899+ ]
864900
865901-- | Pretty print a Parsec ParseError as a Box
866902prettyPrintParseError :: P.ParseError -> Box.Box
@@ -910,8 +946,9 @@ prettyPrintParseErrorMessages msgOr msgUnknown msgExpecting msgUnExpected msgEnd
910946
911947 clean = nub . filter (not . null)
912948
949+-- | Indent to the right, and pad on top and bottom.
913950indent :: Box.Box -> Box.Box
914−indent = Box.moveRight 2
951+indent = Box.moveUp 1 . Box.moveDown 1 . Box.moveRight 2
915952
916953line :: String -> Box.Box
917954line = Box.text