VarDecl.hs revision e1839fb37a3a2ccd457464cb0dcc5efd466dbe22
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerModule : $Header$
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst SchulzCopyright : (c) Christian Maeder and Uni Bremen 2002-2003
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst SchulzLicence : similar to LGPL, see HetCATS/LICENCE.txt or LIZENZ.txt
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst SchulzMaintainer : maeder@tzi.de
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst SchulzStability : provisional
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst SchulzPortability : non-portable (MonadState)
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst Schulzanalyse generic var (or type var) decls
4d82cd7c26bfde17669c8bcb3986d62ef0e47d05Christian Maederimport qualified Common.Lib.Map as Map
4d82cd7c26bfde17669c8bcb3986d62ef0e47d05Christian Maederimport qualified Common.Lib.Set as Set
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst Schulz-- | add diagnostic messages
4d82cd7c26bfde17669c8bcb3986d62ef0e47d05Christian MaederaddDiags :: [Diagnosis] -> State Env ()
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst Schulz put $ e {envDiags = ds ++ envDiags e}
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst Schulz-- | add sentences
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst SchulzappendSentences :: [Named Sentence] -> State Env ()
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst SchulzappendSentences fs =
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst Schulz put $ e {sentences = sentences e ++ fs}
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst SchulzanaStarType :: Type -> State Env (Maybe Type)
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst SchulzanaStarType t = do mp <- fromResult (anaType (Just star, t) . typeMap)
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst Schulz return $ fmap snd mp
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst SchulzanaInstTypes :: [Type] -> State Env [Type]
4d82cd7c26bfde17669c8bcb3986d62ef0e47d05Christian MaederanaInstTypes ts = if null ts then return []
4d82cd7c26bfde17669c8bcb3986d62ef0e47d05Christian Maeder else do mp <- fromResult (anaType (Nothing, head ts) . typeMap)
4442a735444b0696aa5d81e78023a570f17d3a31Christian Maeder rs <- anaInstTypes $ tail ts
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst Schulz return $ case mp of
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst Schulz Nothing -> rs
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst Schulz Just (_, ty) -> ty:rs
4d82cd7c26bfde17669c8bcb3986d62ef0e47d05Christian MaederanaTypeScheme :: TypeScheme -> State Env (Maybe TypeScheme)
4442a735444b0696aa5d81e78023a570f17d3a31Christian MaederanaTypeScheme (TypeScheme tArgs (q :=> ty) p) =
4d82cd7c26bfde17669c8bcb3986d62ef0e47d05Christian Maeder do tm <- gets typeMap -- save global variables
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst Schulz mArgs <- mapM anaTypeVarDecl tArgs
4442a735444b0696aa5d81e78023a570f17d3a31Christian Maeder let newArgs = catMaybes mArgs
4442a735444b0696aa5d81e78023a570f17d3a31Christian Maeder checkUniqueTypevars newArgs
4442a735444b0696aa5d81e78023a570f17d3a31Christian Maeder mt <- anaStarType ty
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst Schulz putTypeMap tm -- forget local variables
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst Schulz Nothing -> return Nothing
75f241761ba1566fbec547ae45d276683e5a8e80Ewaryst Schulz Just newTy -> return $ Just $ TypeScheme newArgs (q :=> newTy) p
24ec53d5bdce82359ca637fc98a17b3023dbd1a5Eugen KuksaanaKind :: Kind -> State Env Kind
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst SchulzanaKind k = toState star $ anaKindM k
75f241761ba1566fbec547ae45d276683e5a8e80Ewaryst SchulztoState :: a -> (Env -> Result a) -> State Env a
f0a8cb240fea2ac6868275be657f48f4470d9932Ewaryst SchulztoState bot r = do
75f241761ba1566fbec547ae45d276683e5a8e80Ewaryst Schulz ma <- fromResult r
case Map.lookup i tk of
Nothing -> putTypeMap $ Map.insert i
Just newDefn -> putTypeMap $ Map.insert i
let l = Map.findWithDefault (OpInfos []) i $ assumps e
if null l then do putAssumps $ Map.insert i
Just oi -> do putAssumps $ Map.insert i
let s = Map.fromAscList $ map ( \ a@(TypeArg i k _ _) ->
Set.toList $ varsOf t
Map.filter (not . null . opInfos) .
Map.map (OpInfos . filter p . opInfos)