on 501c607 help sign in
elk/src/Type/Hint.hs
35 lines 910 B history raw
1module Type.Hint where
3import Control.Applicative ( (<$>) )
4import qualified Data.UnionFind.IO as UF
5import Text.PrettyPrint as P
7import qualified AST.Annotation as A
8import AST.PrettyPrint (pretty)
9import Type.Type (Descriptor, toSrcType)
12type Hint = Doc
15create
16 :: A.Region
17 -> Maybe String
18 -> UF.Point Descriptor
19 -> UF.Point Descriptor
20 -> IO Hint
21create region hint t1 t2 =
22 do t1' <- pretty <$> toSrcType t1
23 t2' <- pretty <$> toSrcType t2
24 return . foldr ($+$) P.empty $
25 [ P.text "Type mismatch between the following types" <+> pretty region <> P.text ":"
26 , P.text ""
27 , P.nest 8 t1'
28 , P.text ""
29 , P.nest 8 t2'
30 , P.text ""
31 , maybe P.empty (P.nest 4 . P.text) hint
32 , P.text " It is related to the following expression:"
33 , P.text ""
34 , P.nest 8 $ A.getRegionDocs region
35 ]