@@ -7,6 +7,8 @@ import qualified Type.State as TS
77import Control.Arrow (first,second)
88import Control.Monad.State
99import SourceSyntax.Location
10+import Type.PrettyPrint
11+import Text.PrettyPrint (render)
1012
1113unify :: SrcSpan -> Variable -> Variable -> StateT TS.SolverState IO ()
1214unify span variable1 variable2 = do
@@ -106,6 +108,12 @@ actuallyUnify span variable1 variable2 = do
106108 List _ -> flexAndUnify varSuper
107109 _ -> comparableError ""
108110
111+ rigidError variable = TS.addError span msg variable1 variable2
112+ where
113+ msg = concat
114+ [ "Cannot unify rigid type variable '", render (pretty Never variable), "'.\n"
115+ , "It is likely that a type annotation is not general enough." ]
116+
109117 superUnify =
110118 case (flex desc1, flex desc2, name desc1, name desc2) of
111119 (Is super1, Is super2, _, _)
@@ -126,6 +134,8 @@ actuallyUnify span variable1 variable2 = do
126134 (Is Appendable, _, _, _) -> unifyAppendable variable1 variable2
127135 (_, Is Appendable, _, _) -> unifyAppendable variable2 variable1
128136
137+ (Rigid, _, _, _) -> rigidError variable1
138+ (_, Rigid, _, _) -> rigidError variable2
129139 _ -> TS.addError span "" variable1 variable2
130140
131141 case (structure desc1, structure desc2) of