on 4bb23bc help sign in
elk/compiler/Types/Hints.hs
27 lines 958 B history raw
1module Types.Hints (hints) where
3import Control.Arrow (first)
4import qualified Data.Map as Map
5import Guid
6import qualified Libraries as Libs
7import Parse.Library (iParse)
8import Parse.Types
9import qualified Types.Substitutions as Subs
10import Types.Types
12hints :: GuidCounter [(String, Scheme)]
13hints = mapM toScheme values
14 where
15 values :: [(String, String)]
16 values = addPrefixes (Map.toList (Map.map Map.toList Libs.libraries))
18 addPrefixes :: [(String,[(String, String)])] -> [(String, String)]
19 addPrefixes = concatMap (\(m,vs) -> map (first (\n -> m ++ "." ++ n)) vs)
21 toScheme :: (String, String) -> GuidCounter (String, Scheme)
22 toScheme (name, tipeString) =
23 let err = "in docs.json parsing type: " ++ tipeString in
24 case iParse (fmap toType typeExpr) err tipeString of
25 Left err -> error (show err)
26 Right tipe -> do scheme <- Subs.generalize [] =<< Subs.superize name tipe
27 return (name, scheme)