on df667ca help sign in
elk/compiler/Types/Hints.hs
32 lines 1.3 kB history raw
1module Types.Hints (hints) where
3import Control.Arrow (first)
4import Control.Monad (liftM)
5import Data.Maybe (catMaybes)
6import qualified Data.Map as Map
7import Guid
8import qualified Libraries as Libs
9import Parse.Library (iParse)
10import Parse.Types
11import qualified Types.Substitutions as Subs
12import Types.Types
14hints :: GuidCounter [(String, Scheme)]
15hints = liftM catMaybes (mapM toScheme values)
16 where
17 values :: [(String, String)]
18 values = addPrefixes (Map.toList (Map.map Map.toList Libs.libraries))
20 addPrefixes :: [(String,[(String, String)])] -> [(String, String)]
21 addPrefixes = concatMap (\(m,vs) -> map (first (\n -> m ++ "." ++ n)) vs)
23 toScheme :: (String, String) -> GuidCounter (Maybe (String, Scheme))
24 toScheme (name, 't':'y':'p':'e':' ':_) = return Nothing
25 toScheme (name, 'd':'a':'t':'a':' ':_) = return Nothing
26 toScheme (name, tipeString) =
27 let err = "compiler error parsing type of " ++ name ++ ":\n" ++ tipeString
28 in case iParse (fmap toType typeExpr) err tipeString of
29 Left err -> error (show err)
30 Right tipe -> do
31 scheme <- Subs.generalize [] =<< Subs.superize name tipe
32 return (Just (name, scheme))