2012-08-09 14:38:18 +00:00
|
|
|
module Types.Hints (hints) where
|
2012-04-19 06:32:10 +00:00
|
|
|
|
2012-05-15 06:12:18 +00:00
|
|
|
import Control.Arrow (first)
|
2013-03-17 05:24:18 +00:00
|
|
|
import qualified Data.Map as Map
|
|
|
|
import Guid
|
2013-04-10 02:50:56 +00:00
|
|
|
import qualified Libraries as Libs
|
2013-03-17 05:24:18 +00:00
|
|
|
import Parse.Library (iParse)
|
|
|
|
import Parse.Types
|
2013-04-10 02:50:56 +00:00
|
|
|
import qualified Types.Substitutions as Subs
|
2012-11-23 04:30:37 +00:00
|
|
|
import Types.Types
|
2012-04-19 06:32:10 +00:00
|
|
|
|
2013-03-17 05:24:18 +00:00
|
|
|
hints :: GuidCounter [(String, Scheme)]
|
|
|
|
hints = mapM toScheme values
|
2013-04-08 00:55:34 +00:00
|
|
|
where
|
2013-04-10 02:50:56 +00:00
|
|
|
values :: [(String, String)]
|
|
|
|
values = addPrefixes (Map.toList (Map.map Map.toList Libs.libraries))
|
2013-04-08 08:48:30 +00:00
|
|
|
|
2013-04-10 02:50:56 +00:00
|
|
|
addPrefixes :: [(String,[(String, String)])] -> [(String, String)]
|
2013-04-08 08:48:30 +00:00
|
|
|
addPrefixes = concatMap (\(m,vs) -> map (first (\n -> m ++ "." ++ n)) vs)
|
|
|
|
|
2013-04-10 02:50:56 +00:00
|
|
|
toScheme :: (String, String) -> GuidCounter (String, Scheme)
|
2013-04-08 00:55:34 +00:00
|
|
|
toScheme (name, tipeString) =
|
2013-05-05 01:19:54 +00:00
|
|
|
let err = "in docs.json parsing type: " ++ tipeString in
|
|
|
|
case iParse (fmap toType typeExpr) err tipeString of
|
|
|
|
Left err -> error (show err)
|
|
|
|
Right tipe -> do scheme <- Subs.generalize [] =<< Subs.superize name tipe
|
|
|
|
return (name, scheme)
|