@@ -12,18 +12,20 @@ import SourceSyntax.Module as Module
1212import qualified SourceSyntax.Expression as Expr
1313import SourceSyntax.Location (Located, noneNoDocs)
1414import SourceSyntax.PrettyPrint
15+import SourceSyntax.Type (Type)
1516import Text.PrettyPrint
1617import qualified Type.State as TS
1718import Type.ExtraChecks (extraChecks)
1819import Control.Monad.State
1920import Control.Arrow (second)
2021import Transform.SortDefinitions as Sort
22+import qualified Data.Traversable as Traverse
2123
2224import System.IO.Unsafe -- Possible to switch over to the ST monad instead of
2325 -- the IO monad. I don't think that'd be worthwhile.
2426
2527
26−infer :: Interfaces -> MetadataModule t v -> Either [Doc] (Map.Map String T.Variable)
28+infer :: Interfaces -> MetadataModule t v -> Either [Doc] (Map.Map String Type)
2729infer interfaces modul = unsafePerformIO $ do
2830 env <- Env.initialEnvironment
2931 (datatypes modul ++ concatMap iAdts (Map.elems interfaces))
@@ -45,8 +47,9 @@ infer interfaces modul = unsafePerformIO $ do
4547 constraint <- environ `fmap` TcExpr.constrain env (program modul) (T.VarN fvar)
4648
4749 state <- execStateT (Solve.solve constraint) TS.initialState
48− let errors = TS.sErrors state
49− if null errors
50− then extraChecks $ Map.difference (TS.sSavedEnv state) header
51− else Left `fmap` sequence (reverse errors)
50+ case TS.sErrors state of
51+ errors@(_:_) -> Left `fmap` sequence (reverse errors)
52+ [] -> let types = Map.difference (TS.sSavedEnv state) header in
53+ do srcTypes <- Traverse.traverse T.toSrcType types
54+ return $ Right srcTypes
5255